#include #include #include #include using namespace std; int a[15][15],u[15],vis[15]; void input(){ a[1][3] = a[3][1] = 2; a[1][9] = a[9][1] = 5; a[1][7] = a[7][1] = 4; a[4][6] = a[6][4] = 5; a[7][9] = a[9][7] = 8; a[2][8] = a[8][2] = 5; a[3][9] = a[9][3] = 6; a[3][7] = a[7][3] = 5; } int main() { input(); int t,k; scanf("%d",&t); while(t--){ int flag = 1; scanf("%d",&k); memset(vis,0,sizeof(vis)); for(int i = 1; i<=k; i++){ scanf("%d",&u[i]); if(u[i]<1||u[i]>9){ flag = 0; } } if(k<4||flag == 0){ printf("invalid\n"); continue; } for(int i = 1; i<=k; i++){ if(vis[u[i]]){ flag = 0; break; } int w = a[u[i]][u[i-1]]; if(!w){ vis[u[i]] = 1; } else if(vis[w]){ vis[u[i]] = 1; } else{ flag = 0; break; } } if(!flag) printf("invalid\n"); else printf("valid\n"); } return 0; }