int main(int argc, char* argv[])
{
		
		int a[200],b[200],c[200],x[200],y[200];
		int i,d,n,e;
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
		scanf ("%d%d%d",&a[i],&b[i],&c[i]);

		if (b[i]==1&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=1;
		if (b[i]==2&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+1;
		if (b[i]==3&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+1;
		if (b[i]==4&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+1;
		if (b[i]==5&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+1;
		if (b[i]==6&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+31+1;
		if (b[i]==7&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+31+30+1;
		if (b[i]==8&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+31+30+31+1;
		if (b[i]==9&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+31+30+31+31+1;
		if (b[i]==10&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+31+30+31+31+30+1;
		if (b[i]==11&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+31+30+31+31+30+31+1;
		if (b[i]==12&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		x[i]=31+28+31+30+31+30+31+31+30+31+30+1;
		if (b[i]==1&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=1;
		if (b[i]==2&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+1;
		if (b[i]==3&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+1;
		if (b[i]==4&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+1;
		if (b[i]==5&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+1;
		if (b[i]==6&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+31+1;
		if (b[i]==7&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+31+30+1;
		if (b[i]==8&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+31+30+31+1;
		if (b[i]==9&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+31+30+31+31+1;
		if (b[i]==10&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+31+30+31+31+30+1;
		if (b[i]==11&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+31+30+31+31+30+31+1;
		if (b[i]==12&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		x[i]=31+29+31+30+31+30+31+31+30+31+30+1;

		if (c[i]==1&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=1;
		if (c[i]==2&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+1;
		if (c[i]==3&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+1;
		if (c[i]==4&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+1;
		if (c[i]==5&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+1;
		if (c[i]==6&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+31+1;
		if (c[i]==7&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+31+30+1;
		if (c[i]==8&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+31+30+31+1;
		if (c[i]==9&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+31+30+31+31+1;
		if (c[i]==10&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+31+30+31+31+30+1;
		if (c[i]==11&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+31+30+31+31+30+31+1;
		if (c[i]==12&&((a[i]%100==0&&a[i]%400!=0)||a[i]%4!=0))
		y[i]=31+28+31+30+31+30+31+31+30+31+30+1;
		if (c[i]==1&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=1;
		if (c[i]==2&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+1;
		if (c[i]==3&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+1;
		if (c[i]==4&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+1;
		if (c[i]==5&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+1;
		if (c[i]==6&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+31+1;
		if (c[i]==7&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+31+30+1;
		if (c[i]==8&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+31+30+31+1;
		if (c[i]==9&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+31+30+31+31+1;
		if (c[i]==10&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+31+30+31+31+30+1;
		if (c[i]==11&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+31+30+31+31+30+31+1;
		if (c[i]==12&&((a[i]%4==0&&a[i]%100!=0)||a[i]%400==0))
		y[i]=31+29+31+30+31+30+31+31+30+31+30+1;
		d=y[i]-x[i];
		e=x[i]-y[i];
		if(d%7==0||e%7==0)	
		printf("YES\n");
		else
			printf("NO\n");
		}
		return 0;
}