#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define fi first
#define sc second
#define endl '\n'
#define gcd(x, y) (__gcd(x, y))
#define lcm(x, y) ((x/gcd(x, y))*y)
#define mem(a,b) memset(a, b, sizeof(a))
#define de(x) cerr<<#x<<" :: "<<x<<" "<<endl
void solve()
{
string s;
cin>>s;
bool mn=false,lo=false,up=false,od=false,sp=false;
if(s.size()>=8)mn=true;
for(int i=0;i<s.size();i++){
if(s[i]>='a'&&s[i]<='z')lo=true;
if(s[i]>='A'&&s[i]<='Z')up=true;
if(s[i]=='1'||s[i]=='2'||s[i]=='3'||s[i]=='4'||s[i]=='5'||s[i]=='6'||s[i]=='7'||s[i]=='8'||s[i]=='9'||s[i]=='0') od=true;
if(s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$'||s[i]=='^'||s[i]=='&'||s[i]=='('||s[i]==')') sp =true;
}
if(mn&&lo&&up&&od&&sp)cout<<"valid"<<endl;
else cout<<"invalid"<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}