#include<bits/stdc++.h>
using namespace std;
int rankof[200005];
int parent[200005];
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 main()
{
int test;
scanf("%d",&test);
while(test--)
{
int N;
scanf("%d",&N);
int id = 1;
char a[21], b[21];
map<string, int>mymap;
mymap.clear();
init(N*2);
for(int i=1; i<=N; i++)
{
scanf("%s %s", a, b);
if(!mymap[a])
mymap[a] = id++;
if(!mymap[b])
mymap[b] = id++;
int u = findnode(mymap[a]);
int v = findnode(mymap[b]);
if(u!=v)
{
rankof[u] = rankof[v] + rankof[u];
parent[v] = parent[u];
}
printf("%d\n",rankof[u]);
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgcmFua29mWzIwMDAwNV07CmludCBwYXJlbnRbMjAwMDA1XTsKCnZvaWQgaW5pdChpbnQgbikKewogICAgZm9yKGludCBpPTE7IGk8PW47IGkrKykKICAgICAgICB7IHBhcmVudFtpXSA9IGk7IHJhbmtvZltpXSA9IDE7IH0KfQoKaW50IGZpbmRub2RlKGludCB4KQp7CiAgICBpZihwYXJlbnRbeF0hPXgpCiAgICAgICAgcGFyZW50W3hdID0gZmluZG5vZGUocGFyZW50W3hdKTsKICAgIHJldHVybiBwYXJlbnRbeF07Cn0KCmludCBtYWluKCkKewogICAgaW50IHRlc3Q7CiAgICBzY2FuZigiJWQiLCZ0ZXN0KTsKICAgIHdoaWxlKHRlc3QtLSkKICAgIHsKICAgICAgICBpbnQgTjsKICAgICAgICBzY2FuZigiJWQiLCZOKTsKICAgICAgICBpbnQgaWQgPSAxOyAKICAgICAgICBjaGFyIGFbMjFdLCBiWzIxXTsKICAgICAgICBtYXA8c3RyaW5nLCBpbnQ+bXltYXA7CiAgICAgICAgbXltYXAuY2xlYXIoKTsKICAgICAgICBpbml0KE4qMik7CiAgICAgICAgZm9yKGludCBpPTE7IGk8PU47IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIHNjYW5mKCIlcyAlcyIsIGEsIGIpOwogICAgICAgICAgICBpZighbXltYXBbYV0pCiAgICAgICAgICAgICAgICBteW1hcFthXSA9IGlkKys7CiAgICAgICAgICAgIGlmKCFteW1hcFtiXSkKICAgICAgICAgICAgICAgIG15bWFwW2JdID0gaWQrKzsKICAgICAgICAgICAgaW50IHUgPSBmaW5kbm9kZShteW1hcFthXSk7CiAgICAgICAgICAgIGludCB2ID0gZmluZG5vZGUobXltYXBbYl0pOwogICAgICAgICAgICBpZih1IT12KQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICByYW5rb2ZbdV0gPSByYW5rb2Zbdl0gKyByYW5rb2ZbdV07CiAgICAgICAgICAgICAgICBwYXJlbnRbdl0gPSBwYXJlbnRbdV07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcHJpbnRmKCIlZFxuIixyYW5rb2ZbdV0pOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9