hdu1260
//
// main.cpp
// hdu1260
//
// Created by Haoying Zhao on 17/9/6.
// Copyright © 2017年 Haoying Zhao. All rights reserved.
//
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a[2005];
int b[2005];
int dp[2005];
for(int i = 0; i < n; ++i) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(dp, 0, sizeof(dp));
int N;
cin >> N;
for(int j = 1; j <= N; ++j)
cin >> a[j];
for(int j = 1; j <= N-1; ++j)
cin >> b[j];
for(int j = 1; j <= N; ++j) {
if(j == 1) {
dp[1] = a[1];
continue;
}
if(dp[j-1] + a[j] <= dp[j-2] + b[j-1])
dp[j] = dp[j-1] + a[j];
else dp[j] = dp[j-2] + b[j-1];
}
int m = 8, n = 0, l = 0;
int flag = 0;
l = dp[N]%60;
n = (dp[N]/60)%60;
m += dp[N]/3600;
if(m > 12) {
m = m-12;
flag = 1;
}
if(m == 0) cout << "00" << ":";
else if(m < 10) cout << "0" << m << ":";
else cout << m << ":";
if(n == 0) cout << "00" << ":";
else if(n < 10) cout << "0" << n << ":";
else cout << n << ":";
if(l == 0) cout << "00" << " ";
else if(l < 10) cout << "0" << l << " ";
else cout << l << " ";
if(flag) cout << "pm" << endl;
else cout << "am" << endl;
}
return 0;
}