def mintime(n, a, b):
if n == 1:
return a[0]
d = [0] * n
d[0] = a[0]
d[1] = min(a[0] + a[1], b[0])
for i in range(2, n):
d[i] = min(d[i-1] + a[i], d[i-2] + b[i-1])
return d[n-1]
def main():
T = int(input().strip(''))
while T > 0:
T -= 1
n = int(input().strip(''))
a = list(map(int, input().strip('').split(' ')))
if n > 1:
b = list(map(int, input().strip('').split(' ')))
else:
b = []
mtime = mintime(n, a, b)
day = mtime//(3600*24)
mtime = mtime%(3600*24)
h = mtime//3600
mtime = mtime%3600
m = mtime//60
mtime = mtime%60
s = mtime
h = (8 + h)%24
hour = str(h) if len(str(h)) == 2 else '0' + str(h)
minute = str(m) if len(str(m)) == 2 else '0' + str(m)
sec = str(s) if len(str(s))==2 else '0' + str(s)
nowtime = hour + ':' + minute + ':' + sec
## 12点算am能过0.9,算pm只过0.55
nowtime = nowtime + ' ' + ('am' if h <= 12 else 'pm')
print(nowtime)
if __name__ == '__main__':
main()
#笔试题目##网易#