#include
#include
#include
#include
#include
#include
using namespace std;
int n, m, k, sum, count;
int num[110000];
int two[110000];
int dp[110000];
int Min( int a, int b )
{
return a>b?b:a;
}
int main()
{
int i, j, q, p, t, flag, cas;
int x, y, z;
scanf( "%d",&t );
while( t-- )
{
scanf( "%d",&n );
for( i=1;i<=n;i++ )
scanf( "%d",&num[i] );
if( n==1 )
{
sum=num[1];
}
else
{
for( i=2;i<=n;i++ )
scanf ( "%d",&two[i] );
memset( dp,0,sizeof( dp ) );
dp[1]=num[1];
dp[2]=Min( two[2],num[1]+num[2] );
for( i=3;i<=n;i++ )
{
dp[i]=Min( dp[i-1]+num[i],dp[i-2]+two[i] );
}
sum=dp[n];
}
int s=sum%60;
int m=( sum-s )%3600/60;
int h=( sum-m*60-s )/3600;
h+=8;
if( h<12 )
{
printf( "%02d:%02d:%02d am\n",h,m,s );
}
else
{
if( h==12 )
printf( "%02d:%02d:%02d pm\n",h,m,s );
else
printf( "%02d:%02d:%02d pm\n",h%12,m,s );
}
}
return 0;
}