#include <stdio.h>
struct Time
{
int year;
int month;
int day;
int hour;
int minute;
int second;
};
void getTime(struct Time *pt);
int dayOfYear(struct Time t);
long secondOfyear(struct Time *pt);
int main()
{
struct Time t;
int i,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
getTime(&t);
printf("%d %ld\n",dayOfYear(t),secondOfyear(&t));
}
return 0;
}
void getTime(struct Time *pt)
{
scanf("%d%d%d%d%d%d", &pt->year, &pt->month, &pt->day, &pt->hour, &pt->minute, &pt->second);
return;
}
int dayOfYear(struct Time t)
{
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int i,sum=0;
if(t.year%400==0||(t.year%4==0&&t.year%100!=0))
a[1]++;
for(i=0;i<t.month-1;i++)
sum+=a[i];
sum+=t.day;
return sum;
}
long secondOfyear(struct Time *pt)
{
long sum=0;
int x=dayOfYear(*pt);
sum=x*24*3600+pt->hour*3600+pt->minute*60+pt->second;
return sum;
}