for _ in range(int(input())): clothes = {} for _ in range(int(input())): name, type = input().split() clothes[type] = clothes.get(type,0) + 1 result = 1 for n in clothes.values(): result *= (n+1) print(result-1)