#include <iostream> #include<math.h> using namespace std; int main() { int n,y,m,d,c,w,t; cin>>t; while(t--) { cin>>y>>m>>d; if(m<=2) { m+=12; y=y-1; } c=y/100; y=y%100; w=c/4-2*c+y+y/4+13*(m+1)/5+d-1; w%=7; if(w<=0) w+=7; cout<<w<<endl; } return 0; }