#include<bits/stdc++.h>
using namespace std;
int rankof[800005];
int parent[800005];
string ht[800005];
void init(int n)
{
for(int i=1; i<=n; i++)
{ parent[i] = i; rankof[i] = 1; }
}
int findnode(int x)
{
if(parent[x]!=x)
parent[x] = findnode(parent[x]);
return parent[x];
}
int hash(string& s) {
int h = 1;
for (int i = 0; i < s.length(); i++) {
h = h * 23 + s[i];
h %= 600000;
}
while (ht[h] != "" && ht[h] != s) h++;
if (ht[h] == "") ht[h] = s;
return h;
}
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
int N;
scanf("%d",&N);
int id = 1; string a, b;
init(800000);
for(int i=1; i<=N; i++)
{
cin >> a >> b;
int u = findnode(hash(a));
int v = findnode(hash(b));
if(u!=v)
{
rankof[u] = rankof[v] + rankof[u];
parent[v] = parent[u];
}
printf("%d\n",rankof[u]);
}
}
return 0;
}
ICAgICNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CgogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiAgICBpbnQgcmFua29mWzgwMDAwNV07CiAgICBpbnQgcGFyZW50WzgwMDAwNV07CiAgICBzdHJpbmcgaHRbODAwMDA1XTsKICAgIHZvaWQgaW5pdChpbnQgbikKICAgIHsKICAgICAgICBmb3IoaW50IGk9MTsgaTw9bjsgaSsrKQogICAgICAgICAgICB7IHBhcmVudFtpXSA9IGk7IHJhbmtvZltpXSA9IDE7IH0KICAgIH0KCiAgICBpbnQgZmluZG5vZGUoaW50IHgpCiAgICB7CiAgICAgICAgaWYocGFyZW50W3hdIT14KQogICAgICAgICAgICBwYXJlbnRbeF0gPSBmaW5kbm9kZShwYXJlbnRbeF0pOwogICAgICAgIHJldHVybiBwYXJlbnRbeF07CiAgICB9CgogICAgaW50IGhhc2goc3RyaW5nJiBzKSB7CiAgICAgIGludCBoID0gMTsKICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzLmxlbmd0aCgpOyBpKyspIHsKICAgICAgICBoID0gaCAqIDIzICsgc1tpXTsKICAgICAgICBoICU9IDYwMDAwMDsKICAgICAgfQogICAgICB3aGlsZSAoaHRbaF0gIT0gIiIgJiYgaHRbaF0gIT0gcykgaCsrOwogICAgICBpZiAoaHRbaF0gPT0gIiIpIGh0W2hdID0gczsKICAgICAgcmV0dXJuIGg7CiAgICB9CiAgICAKICAgIAogICAgaW50IG1haW4oKQogICAgewogICAgICAgIGludCB0ZXN0OwogICAgICAgIHNjYW5mKCIlZCIsJnRlc3QpOwogICAgICAgIHdoaWxlKHRlc3QtLSkKICAgICAgICB7CiAgICAgICAgICAgIGludCBOOwogICAgICAgICAgICBzY2FuZigiJWQiLCZOKTsKICAgICAgICAgICAgaW50IGlkID0gMTsgc3RyaW5nIGEsIGI7CiAgICAgICAgICAgIGluaXQoODAwMDAwKTsKICAgICAgICAgICAgZm9yKGludCBpPTE7IGk8PU47IGkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY2luID4+IGEgPj4gYjsKICAgICAgICAgICAgICAgIGludCB1ID0gZmluZG5vZGUoaGFzaChhKSk7CiAgICAgICAgICAgICAgICBpbnQgdiA9IGZpbmRub2RlKGhhc2goYikpOwogICAgICAgICAgICAgICAgaWYodSE9dikKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICByYW5rb2ZbdV0gPSByYW5rb2Zbdl0gKyByYW5rb2ZbdV07CiAgICAgICAgICAgICAgICAgICAgcGFyZW50W3ZdID0gcGFyZW50W3VdOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcHJpbnRmKCIlZFxuIixyYW5rb2ZbdV0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgfQo=