#include <iostream>
using namespace std;

bool isRunNian(int year){
    if(year%400 == 0)return 1;
    if(year%4 == 0 && year%100 !=0)return 1;
    return 0;
}

int main() {
    int n;cin>>n;
    while(n--){
        int year,month,day;
        int arr[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        cin>>year>>month>>day;
        if(isRunNian(year))arr[2]++;
        //判断天数
        int pastDays = 0;
        for(int i =1;i<month;i++)
            pastDays+=arr[i];
        pastDays+=day;
        cout<<pastDays<<endl;
    }
}
// 64 位输出请用 printf("%lld")

qd