#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector S; map mp; for (int i = 0; i < N; i++) { string a, b; cin >> a >> b; S.emplace_back(b); mp[a] = false; if (mp.find(b) == mp.end() || mp[b]) mp[b] = true; } for (auto s : S) { if (mp[s]) { cout << s << '\n'; mp[s] = false; } } return 0; }