def prime(x): if x<=3: return x>1 if x%2==0 or x%3==0: return False i = 5 while i ** 2 <= x: if x % i == 0 or x % (i + 2) == 0: return False i += 6 return True def combining2(data,value1,newdata): if not data : return else : for j,value in enumerate(data): data2 = data.copy() del data2[j] value2 = value1 + value newdata.append(int(value2)) others = combining2(data2,value2,newdata) return newdata n = int(input()) responses = [] for i in range(n): numbers = input() array = list(numbers) newarray = [] value = '' answer = set(combining2(array, value, newarray)) prime_nb = 0 for x in answer : if prime(x): prime_nb +=1 responses.append(prime_nb) for response in responses: print(response)