#include<stdio.h>
int isRun(int year){
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return 1;
return 0;
}
int main(){
int t;
scanf("%d", &t);
while (t--){
int month[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int a, b, c;
int sum = 0, i;
scanf("%d%d%d", &a, &b, &c);
if (isRun(a))
month[2] = 29;
for (i = 1; i < b; i++){
sum += month[i];
}
printf("%d\n", sum + c);
}
return 0;
}
int isRun(int year){
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return 1;
return 0;
}
int main(){
int t;
scanf("%d", &t);
while (t--){
int month[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int a, b, c;
int sum = 0, i;
scanf("%d%d%d", &a, &b, &c);
if (isRun(a))
month[2] = 29;
for (i = 1; i < b; i++){
sum += month[i];
}
printf("%d\n", sum + c);
}
return 0;
}