numbers = "0123456789" lower_case = "abcdefghijklmnopqrstuvwxyz" upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" special_characters = "!@#$%^&*()-+" t=input() for _ in range(t): n = raw_input() up=0 lo=0 sp=0 nm=0 c=0 for item in n: if item in numbers: nm+=1 elif item in upper_case: up+=1 elif item in lower_case: lo+=1 elif item in special_characters: sp+=1 if not up: c+=1 if not lo: c+=1 if not nm: c+=1 if not sp: c+=1 if len(n)+c<6: c=c+(6-len(n)-c) print c