#include<stdio.h>
#define Max 100

int output(int y, int m, int d){
  int count=0;
  while(1){
    if(y == 1 && m == 1 && d == 1)break;
    count++;
    d--;
    if(d<1){
      m--;
      if(m<1){
	y--;
	m=10;
      }
      if(m%2==1 || y%3 == 0)d=20;
      else d=19;
    }

  }
  return count;
}

int main(){
  int year[Max],month[Max],day[Max];
  int i,n;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d %d %d",&year[i],&month[i],&day[i]);
  }

  for(i = 0; i < n; i++){
    printf("%d",  196470-output(year[i],month[i],day[i]));
    puts("");
  }
  return 0;
}