# Import the re module for regular expressions
import re
# Define a function to check the validity of a password
def is_valid(password):
# Use re.search to check if the password contains at least one lowercase letter
if not re.search("[a-z]", password):
return False
# Use re.search to check if the password contains at least one uppercase letter
if not re.search("[A-Z]", password):
return False
# Use re.search to check if the password contains at least one digit
if not re.search("[0-9]", password):
return False
# Use re.search to check if the password contains at least one special character
if not re.search("[!@#$%^&*()]", password):
return False
# Use len to check if the password has a minimum length of 8 characters
if len(password) < 8:
return False
# If all the conditions are met, return True
return True
# Take the input of the number of cases to check
T = int(input())
# Use a for loop to iterate over T times
for i in range(T):
# Take the input of the password string
password = input()
# Call the validity function with the password string
valid = is_valid(password)
# Print the output accordingly
if valid:
print("valid")
else:
print("invalid")