#include<iostream>
#include <unordered_map>
#include<algorithm>
using namespace std;
unordered_map<string, string> father;
string find(string x)
{
if (father[x] == x)return x;
else
{
father[x] = find(father[x]);
return father[x];
}
}
void merge(string x,string y)
{
x = find(x); y = find(y);
father[y] = x;
}
bool lian(string x,string y)
{
x = find(x); y = find(y);
return x == y;
}
int main()
{
string s, h; int n; char c; char b[100];
cin >> n;
while(n--)
{
cin >> s >> h;
if (father.find(s) == father.end())father[s]=s;
if (father.find(h) == father.end())father[h]=h;
merge(s, h);
}
return 0;
}