#include #include char s1[101]; char s2[]="anniversary"; int dp[101][12][2]; int ls1,ls2; void update(int &a,int b) { if (a==-1||a>b) a=b; } int main() { int t,i,j; scanf("%d",&t); while (t--) { scanf("%s",s1); ls1=strlen(s1); ls2=strlen(s2); memset(dp,-1,sizeof(dp)); for (i=0;i<=ls1;i++) dp[i][0][0]=0; for (i=1;i<=ls1;i++) { for (j=1;j<=ls2;j++) { if (~dp[i-1][j][0]) update(dp[i][j][0],dp[i-1][j][0]); if (~dp[i-1][j][1]) update(dp[i][j][0],dp[i-1][j][1]); if (s1[i-1]==s2[j-1]) { if (~dp[i-1][j-1][1]) update(dp[i][j][1],dp[i-1][j-1][1]); if (~dp[i-1][j-1][0]) update(dp[i][j][1],dp[i-1][j-1][0]+1); } //printf("%d %d %d %d\n",i,j,dp[i][j][0],dp[i][j][1]); } } int ans=-1; if (~dp[ls1][ls2][0]) update(ans,dp[ls1][ls2][0]); if (~dp[ls1][ls2][1]) update(ans,dp[ls1][ls2][1]); if (ans!=-1&&ans<=3&&ls2>=3) printf("YES\n"); else printf("NO\n"); } return 0; }