#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; string a, b;
map<string, int>mymap;
mymap.clear();
init(N*2);
for(int i=1; i<=N; i++)
{
cin>>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;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgcmFua29mWzIwMDAwNV07CmludCBwYXJlbnRbMjAwMDA1XTsKCnZvaWQgaW5pdChpbnQgbikKewogICAgZm9yKGludCBpPTE7IGk8PW47IGkrKykKICAgICAgICB7IHBhcmVudFtpXSA9IGk7IHJhbmtvZltpXSA9IDE7IH0KfQoKaW50IGZpbmRub2RlKGludCB4KQp7CiAgICBpZihwYXJlbnRbeF0hPXgpCiAgICAgICAgcGFyZW50W3hdID0gZmluZG5vZGUocGFyZW50W3hdKTsKICAgIHJldHVybiBwYXJlbnRbeF07Cn0KCmludCBtYWluKCkKewogICAgaW50IHRlc3Q7CiAgICBzY2FuZigiJWQiLCZ0ZXN0KTsKICAgIHdoaWxlKHRlc3QtLSkKICAgIHsKICAgICAgICBpbnQgTjsKICAgICAgICBzY2FuZigiJWQiLCZOKTsKICAgICAgICBpbnQgaWQgPSAxOyBzdHJpbmcgYSwgYjsKICAgICAgICBtYXA8c3RyaW5nLCBpbnQ+bXltYXA7CiAgICAgICAgbXltYXAuY2xlYXIoKTsKICAgICAgICBpbml0KE4qMik7CiAgICAgICAgZm9yKGludCBpPTE7IGk8PU47IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGNpbj4+YT4+YjsKICAgICAgICAgICAgaWYoIW15bWFwW2FdKQogICAgICAgICAgICAgICAgbXltYXBbYV0gPSBpZCsrOwogICAgICAgICAgICBpZighbXltYXBbYl0pCiAgICAgICAgICAgICAgICBteW1hcFtiXSA9IGlkKys7CiAgICAgICAgICAgIGludCB1ID0gZmluZG5vZGUobXltYXBbYV0pOwogICAgICAgICAgICBpbnQgdiA9IGZpbmRub2RlKG15bWFwW2JdKTsKICAgICAgICAgICAgaWYodSE9dikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcmFua29mW3VdID0gcmFua29mW3ZdICsgcmFua29mW3VdOwogICAgICAgICAgICAgICAgcGFyZW50W3ZdID0gcGFyZW50W3VdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHByaW50ZigiJWRcbiIscmFua29mW3VdKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQo=