#include <stdio.h>

int calcDate(int y, int m, int d){
  int i, days=0;

  for(i=1;i<y;i++){
    if(i%3==0){
      days += 200;
    }else{
      days += 195;
    }
  }

  for(i=1;i<m;i++){
    if(i%2==1 || y%3==0){
      days += 20;
    }else{
      days += 19;
    }
  }

  days += d-1;

  return days;
}

int main(){
  int i, n, y, m, d, seed;

  seed = calcDate(1000, 1, 1);

  scanf("%d", &n);
  int days[n];

  for(i=0;i<n;i++){
    scanf("%d", &y);
    scanf("%d", &m);
    scanf("%d", &d);
    days[i] = seed - calcDate(y, m, d);
  }

  for(i=0;i<n;i++){
    printf("%d\n", days[i]);
  }

  return 0;
}