#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string temp;
vector <string> r(n); //의상 종류 저장
for (int i = 0; i < n; i++)
cin >> temp >> r[i];
vector <string> a(r); //벡터 r 복사
sort(r.begin(), r.end()); //오름차순으로 정렬
r.erase(unique(r.begin(), r.end()), r.end()); //중복 제거
vector <int> q(n);
for (int i = 0; i < r.size(); i++) //의상 종류당 갯수 확인
for (int j = 0; j < n; j++)
if (r[i] == a[j])
q[i]++;
int sum = 1;
for (int i = 0; i < r.size(); i++) // (의상 종류당 갯수 + 해당 옷)
sum *= (q[i] + 1);
cout << sum - 1 << endl; //알몸인 상태 제거
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKHZvaWQpIHsKCWludCB0OwoJY2luID4+IHQ7CgoJd2hpbGUgKHQtLSkKCXsKCQlpbnQgbjsKCQljaW4gPj4gbjsKCQlzdHJpbmcgdGVtcDsKCQl2ZWN0b3IgPHN0cmluZz4gcihuKTsJCS8v7J2Y7IOBIOyiheulmCDsoIDsnqUKCQlmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKCQkJY2luID4+IHRlbXAgPj4gcltpXTsKCgkJdmVjdG9yIDxzdHJpbmc+IGEocik7CQkvL+uyoe2EsCByIOuzteyCrAoKCQlzb3J0KHIuYmVnaW4oKSwgci5lbmQoKSk7CS8v7Jik66aE7LCo7Iic7Jy866GcIOygleugrCAKCQlyLmVyYXNlKHVuaXF1ZShyLmJlZ2luKCksIHIuZW5kKCkpLCByLmVuZCgpKTsgLy/spJHrs7Ug7KCc6rGwCgkJCgkJdmVjdG9yIDxpbnQ+IHEobik7CgkJZm9yIChpbnQgaSA9IDA7IGkgPCByLnNpemUoKTsgaSsrKQkvL+ydmOyDgSDsooXrpZjri7kg6r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