# 9375번. 패션왕 신해빈
fromitertoolsimportcombinationsfromitertoolsimportproductfromcollectionsimportdefaultdictimportsysinput=sys.stdin.readlinet=int(input())for_inrange(t):n=int(input())cDict={}ans=1foriinrange(n):name,kind=input().rstrip().split()ifkindnotincDict:cDict[kind]=1else:cDict[kind]+=1forkeyincDict.keys():ans=ans*(cDict[key]+1)# 입는 것 + 안 입는 것
print(ans-1)# 알몸인 경우 -1