#include <iostream>
using namespace std;

int n;
char c1,c2,c3,c4,c5;

bool solve()
{
    c1 -= '0';
    c2 -= '0';
    c4 -= '0';
    c5 -= '0';

    if(c1 == 2 && c2 > 4) return true;
    if(c1 > 2) return true;
    if(c4 > 5) return true;
    if(c4 == 0 && c5 == 0) return false;
    if(c1 == c4 && c2 == c5) return false;
    if(c1 == c5 && c2 == c4) return false;
    if(c1 == c2 - 1 && c2 == c4 - 1 && c4 == c5 - 1) return false;

    int x = c1 * 1000 + c2 * 100 + c4 * 10 + c5;
    int p = 512;
    while(p < x)
    {
        p <<= 1;
        if(p == x) return false;
    }

    return true;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>c1>>c2>>c3>>c4>>c5;
        if(solve()) cout<<"NO\n";
        else cout<<"YES\n";
    }

    return 0;
}