#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, y, m, d;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> y >> m >> d;
    int cnt = 0;
    while(!(y == 1000 && m == 1 && d == 1)){
      cnt++;
      d++;
      if(y%3 == 0){
	if(d == 21)d = 1, m++;
	if(m == 11)m = 1, y++;
      }else{
	if(m%2 == 0){
	  if(d == 20)d = 1, m++;
	}else{
	  if(d == 21)d = 1, m++;
	}
	if(m == 11)m = 1, y++;
      }
    }
    cout << cnt << endl;
  }
}