#include<stdio.h>
int main()
{
  int n;
  int y,m,d;
  int day=0;//count

  int date[3][10]={ {20,20,20,20,20,20,20,20,20,20},
		    {20,19,20,19,20,19,20,19,20,19},
		    {20,19,20,19,20,19,20,19,20,19} };

  scanf("%d",&n);
  for(;n>0;n--){
    scanf("%d %d %d",&y,&m,&d);
    day=date[y%3][m-1]-d;
    m++;
    d=0;
    if(m==11){
      y++;
      m=1;
    }
    if(y==1000)//999??´10?????????????????´???
      printf("%d\n", day+1);
    else{//????????\???

      while(1){
	day+=date[y%3][m-1];
	m++;   
	if(m==11){
	  y++;
	  m=1;
	}
	if(y==1000)	  
	  break;
      }
    printf("%d\n",day+1);
    }
  }
}