#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
int year,yue,ri,ds;
};
struct node1{
node x;
friend bool operator<(node1 a,node1 b){
if(a.x.year==b.x.year){
if(a.x.yue==b.x.yue){
return a.x.ri>b.x.ri;
}else if(a.x.ri!=b.x.ri){
return a.x.yue>b.x.yue;
}else{
return a.x.ds>b.x.ds;
}
}else{
return a.x.year>b.x.year;
}
}
};
map <node1,bool>mp;
bool nian(int x){
if(x%4==0&&x%100!=0||x%400==0) return true;
else return false;
}
bool pd(node x){
if(x.yue==2){
if(nian(x.year)){
return x.ri<=29;
}else{
return x.ri<=28;
}
}else{
if(x.yue==1||x.yue==3||x.yue==5||x.yue==7||x.yue==8||x.yue==10||x.yue==12) return x.ri<=31;
else return x.ri<=30;
}
}
bool yf(int x){
return x<=12;
}
bool hf(node x){
if(x.yue>12||x.ri>31) return false;
if(nian(x.year)){
if(x.yue==2){
return x.ri<=29;
}else{
if(x.yue==1||x.yue==3||x.yue==5||x.yue==7||x.yue==8||x.yue==10||x.yue==12) return x.ri<=31;
else return x.ri<=30;
}
}else{
if(x.yue==2){
return x.ri<=28;
}else{
if(x.yue==1||x.yue==3||x.yue==5||x.yue==7||x.yue==8||x.yue==10||x.yue==12) return x.ri<=31;
else return x.ri<=30;
}
}
}
bool flag;
node hs={2006,11,4,1};
void dfs(node x,int cnt){
if(x.year==hs.year&&x.yue==hs.yue&&x.ri==hs.ri){
if(x.ds==0||cnt==0){
flag=true;
}
return;
}
if(flag) return;
if(x.year>hs.year) return;
if(mp[{x}]==false){
mp[{x}]=true;
}else{
return;
}
node next1=x,next2=x;
next1.ri++;
next1.ds=(next1.ds==0?1:0);
if(!pd(next1)){
next1.ri=1;
next1.yue++;
if(!yf(next1.yue)){
next1.yue=1;
next1.year++;
}
}
next2.yue++;
next2.ds=(next2.ds==0?1:0);
if(!yf(next2.yue)){
next2.yue=1;
next2.year++;
}
if(hf(next1)) dfs(next1,cnt+1);
if(flag) return;
if(hf(next2)) dfs(next2,cnt+1);
}
signed main(){
int t;
cin>>t;
while(t--){
node x1;
flag=false;
mp.clear();
cin>>x1.year>>x1.yue>>x1.ri;
x1.ds=1;
dfs(x1,0);
cout<<(flag==false?"NO":"YES")<<"\n";
}
}