#include<stdio.h>
int main(){
int row;
int year,month,day;
scanf("%d",&row);
while(row--){
int sum=0;
scanf("%d%d%d",&year,&month,&day);
switch(month){
case 1: sum = 0;break;
case 2: sum += 31;break;
case 3: sum += 31+28;break;
case 4: sum += 31*2+28;break;
case 5: sum += 31*2+28+30;break;
case 6: sum += 31*3+28+30;break;
case 7: sum += 31*3+28+30*2;break;
case 8: sum += 31*4+28+30*2;break;
case 9: sum += 31*4+28+30*3;break;
case 10: sum += 31*5+28+30*3;break;
case 11: sum += 31*5+28+30*4;break;
case 12: sum += 31*6+28+30*4;break;
}
if(month>2){
if((year%4 == 0&&year%100 != 0)||(year%400 == 0))
printf("%d\n",sum+1+day);
else printf("%d\n",sum+day);
}
else printf("%d\n",sum+day);
}
return 0;
}
if((year%4 == 0&&year%100 != 0)||(year%400 == 0))
leap = 1; //闰年
else leap = 0; //非闰年