#include <bits/stdc++.h>
#define MAX 20
using namespace std;

int a1[13] = {0,31,28,31,30,31,30,31,31,30,31,30};
int a2[13] = {0,31,29,31,30,31,30,31,31,30,31,30};

bool isrun(int y){
	if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
		return true;
	else
	 	return false;
}

int main(){
	int cnt,m,y,d;
	cin>>cnt;
	while(cnt--){
		cin>>y>>m>>d;
		bool flag = isrun(y);
		int sum = 0;
		if(flag){	//闰年 
			for(int i = 1; i < m; i++){
				sum += a2[i]; 
			}
		}else{
			for(int i = 1; i < m; i++){
				sum += a1[i]; 
			}
		}	
		sum += d;
		cout<<sum<<endl;
	}
}