#include #include #include using namespace std; int main() { char s[6]; int n, i; cin >> n; for (i = 1; i <= n; i++) { cin >> s; if (s[0]<'0' || s[0]>'2' || s[1]<'0' || s[1]>'9' || s[3]<'0' || s[3]>'9' || s[4]<'0' || s[4]>'9') cout << "NO"; else if (s[3]=='0'&&s[4]=='0') cout << "YES"; else if (s[0] == s[1] - 1 && s[1] == s[3] - 1 && s[3] == s[4] - 1) cout << "YES"; else if (s[0] == s[3] && s[1] == s[4]) cout << "YES"; else if (s[0] == s[4] && s[1] == s[3]) cout << "YES"; else { int x; x = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[3] - '0') * 10 + (s[4] - '0'); int y = x; x = x&(x - 1); if (x == 0&&y>=1024) cout << "YES"; else cout << "NO"; } cout << "\n"; } }