#include<stdio.h>

int CalculateBirthday(int, int, int);

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

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d %d %d", &y, &m, &d);
    ans = CalculateBirthday(y, m, d);
    printf("%d\n", ans);
  }
  return 0;
}

int CalculateBirthday(int y, int m, int d){
  int i, ans;

  if(y%3 == 0){
    ans = 21-d + (10-m)*20;
  }else{
    ans = 21-d;
    if(m%2 == 0) ans--;
    for(i=m+1; i<=10; i++){
      ans += 20;
      if(i%2 == 0) ans--;
    }
  }
  for(i=y+1; i<1000; i++){
    if(i%3 == 0) ans += 200;
    else ans += 195;
  }
  return ans;
}