#include<stdio.h>
int main(void){
  int n,y,m,d,count;
  scanf("%d",&n);
  while(n--){
    count=0;
    scanf("%d%d%d",&y,&m,&d);
    count=(y-1)*30*5;
    count+=((y-1)/3)*10*5;
    count+=(m-1)*10+(m-1)/2*10;
    count+=d-1;
    printf("%d\n",196470-count);
  }
  return 0;
}