#include <stdio.h>
#define MAX 1000

int main() {
  int i, j, n, Y[MAX], M[MAX], D[MAX], sum[MAX];
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    sum[i]=0;
    scanf("%d %d %d", &Y[i], &M[i], &D[i]);
    for(j=Y[i]+1; j<1000; j++) {
      if(j%3 == 0) sum[i] += 200;
      else sum[i] += 195;
    }
    if(Y[i]%3 == 0) {
      sum[i] += 21-D[i];
      sum[i] += (10-M[i])*20;
    } else {
      if(M[i]%2 != 0) sum[i] += 21-D[i];
      else sum[i] += 20-D[i];
      for(j=M[i]+1; j<11; j++) {
	if(j%2 != 0) sum[i] += 20;
	else sum[i] += 19;
      }
    }
  }
  for(i=0; i<n; i++) {
    printf("%d\n",sum[i]);
  }
  return 0;
}
