times=int(input()) def credit(n): if n%10==0: return "Valid" else: return "Invalid" for t in range(times): p=list(map(int,input().split())) k=[] l=[] for j in p:#有對應到的數字 k.append(j//1000*2) k.append(j//10%10*2) k=[a//10+a%10 for a in k] for i in p:#沒對應到的數字 l.append(i//100%10) l.append(i%10) print(credit(sum(k)+sum(l)))