#include <stdio.h>
#include <string.h>
int main() {
int t;
scanf("%d",&t);
for(int j=0;j<t;j++){
char str[101];
scanf("%s",&str);
int lwr=0,upr=0,dgt=0,sp_char=0;
for(int i=0;i<strlen(str);i++){
if(str[i]>='a' && str[i]<='z'){
lwr=1;
}
else if(str[i]>='A' && str[i]<='Z'){
upr=1;
}
else if(str[i]>='0' && str[i]<='9'){
dgt=1;
}
else if(str[i]=='!' || str[i]=='@' ||str[i]=='#' || str[i]=='$' ||
str[i]=='%' || str[i]=='^' || str[i]=='&' || str[i]=='*' || str[i]=='(' || str[i]==')'){
sp_char=1;
}
}
if (strlen(str)>=8 && lwr && upr && dgt && sp_char) {
printf("valid\n");
} else {
printf("invalid\n");
}
}
return 0;
}