#include <iostream>

using namespace std;
int main(){
    int daytab[2][13]={
        {0,31,28,31,30,31,30,31,31,30,31,30,31},
        {0,31,29,31,30,31,30,31,31,30,31,30,31}
        };
    int year,month,day;
    int eat;
    cin>>eat;   // 我太懒了,直接把输入数据量吃掉,懒得改下面了
    while(cin>>year>>month>>day){
        int today=1,yearFlag=0,m=1,d=1;
        if(year%400==0||(year%100!=0&&year%4==0)) yearFlag=1;
        while(m!=month||d!=day){
            today++;
            d++;
            if(d>daytab[yearFlag][m]){
                m++;
                d=1;
            }
        }
        cout<<today<<endl;

    }

}