#include <stdio.h>
 
int calc(int,int,int);
 
int main(){
  int N,Y,M,D;
  scanf("%d",&N);
  while(N--){
    scanf("%d%d%d",&Y,&M,&D);
    printf("%d\n",calc(Y,M,D));
  }
  return 0;
}
 
int calc(int Y,int M,int D){
  int cnt = 0;
  int y = 1000,m = 1,d = 1;
  while(1){
    if(Y == y && M == m && D == d){
      break;
    }
    D++; cnt++;
    if((Y%3 == 0 || M%2) && D == 21){
      D = 1; M++;
    }else if(Y % 3 != 0 && M%2 == 0 && D == 20){
      D = 1; M++;
    }
    if(M == 11){ M = 1; Y++; }
  }
  return cnt;
}