#include #include using namespace std; const int G[10][10]={ 0,0,0,0,0,0,0,0,0,0, 0,0,0,2,0,0,0,4,0,5, 0,0,0,0,0,0,0,0,5,0, 0,2,0,0,0,0,0,5,0,6, 0,0,0,0,0,0,5,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,5,0,0,0,0,0, 0,4,0,5,0,0,0,0,0,8, 0,0,5,0,0,0,0,0,0,0, 0,5,0,6,0,0,0,8,0,0, }; int T,s[10],n,k,i,j; bool vis[10],flag; int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); memset(vis,false,sizeof(vis)); vis[0]=true; flag=true; for(i=1;i<=n;i++) { scanf("%d",&s[i]); if(s[i]>9||s[i]<=0)flag=false; } if(flag==false||i!=n+1||n<4){puts("invalid");continue;} for(i=1;i<=n;i++) { if(vis[s[i]]){puts("invalid");break;} if(!vis[G[s[i]][s[i-1]]]){puts("invalid");break;} vis[s[i]]=true; } if(i==n+1)puts("valid"); } return 0; }