#include <stdio.h>

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

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d %d %d", &y, &m, &d);
    printf("%d\n", 196471
	          -((y-1)*195 + (y-1)/3*5)
                  -((y%3==0) ? (m-1)*20 : (m-1)*20-(m-1)/2)
                  -d
      );
  }

  return 0;
}