#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int((x).size())) #define bit(x) (1 << (x)) #define cnt1(x) (__builtin_popcount(x)) template inline void chkmax(T& x, T y) { if (x < y) x = y; } template inline void chkmin(T& x, T y) { if (y < x) x = y; } typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; const int MX = 105; char s[MX]; int n; char t[] = "anniversary"; int dp[MX][11][3]; int calc(int n, int m, int k) { int& val = dp[n][m][k]; if (val != -1) return val; if (!m) return val = (k == 0); if (!n || !k) return val = 0; if (calc(n - 1, m, k)) return val = 1; for (int j = 1; j <= min(n, m); j++) { if (strncmp(s + n - j + 1, t + m - j, j)) continue; if (calc(n - j, m - j, k - 1)) return val = 1; } return val = 0; } int main() { int tc; for (scanf("%d", &tc); tc--; ) { scanf("%s", s + 1); n = strlen(s + 1); memset(dp, -1, sizeof dp); puts(calc(n, 11, 3) ? "YES" : "NO"); } return 0; }