https://www.acmicpc.net/problem/9375
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void)
{
int T, N;
string str1, str2;
cin >> T;
for (int t = 0; t < T; t++)
{
map<string, vector<string>> m;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> str1 >> str2;
m[str2].push_back(str1);
}
int answer = 1;
for (auto str_vec : m)
{
answer *= (str_vec.second.size() + 1);
}
cout << answer - 1 << endl;
}
return 0;
}