#include <cstdio>
#include <cassert>

using namespace std;


int main()
{
	int n;
	scanf ("%d", &n);
	while (n--)
	{
		int h, m;
		scanf ("%d:%d", &h, &m);
		int x = h/10, y=h%10, z=m/10, t=m%10;
		if (!(x*10+y>=0 && x*10+y<24 && z*10+t>=0 &&z*10+t <60)) {
			printf ("NO\n");
			continue;
		}

		if ((z == 0 && t == 0) ||
			(x==z && y == t) ||
			(x == t && y== z) ||
			(y == x+1 && z == y+1 && t == z+1))
		{
			printf ("YES\n");
			continue;
		}

		if (x == 0)
		{
			printf ("NO\n");
			continue;
		}
		int p = x*1000+y*100+z*10+t;
		int v;
		for (v = 1; v < p; v*=2);
		if (v==p)
		{
			printf ("YES\n");
		} else {
			printf ("NO\n");
		}
	}
	return 0;
}