import sys
N = int(sys.stdin.readline().rstrip())
for _ in range(N):
map_list = {}
n = int(sys.stdin.readline().rstrip())
for i in range(n):
a, b = sys.stdin.readline().rstrip().split()
if b not in map_list:
map_list[b] = 1
else:
map_list[b] += 1
num = 1
for key in map_list:
num *= (map_list[key] + 1)
print(num -1)
맵으로 키를 옷의 종류로, 값으로 개수를 줘서 풀었다. 경우의 수를 구하고 마지막에 아무것도 입지 않는 경우의 수 1 빼주면 된다.