#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > adj(100);
map<int , bool> mp;
void print(int node , vector<int> &path){
path.push_back(node);
if(adj[node].size() == 0 && mp[node] == false){
mp[node] = true;
for(int i : path) cout << i << " ";
cout << endl;
}else{
for(int i : adj[node]){
print(i , path);
}
}
path.pop_back();
}
void solve(){
vector<int> path;
print(1 , path);
}
int main(){
int n; cin >> n;
for(int i = 0; i < n; i++){
int a,b; cin >> a >> b;
adj[a].push_back(b);
}
solve();
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2ZWN0b3I8dmVjdG9yPGludD4gPiBhZGooMTAwKTsKCm1hcDxpbnQgLCBib29sPiBtcDsKCnZvaWQgcHJpbnQoaW50IG5vZGUgLCB2ZWN0b3I8aW50PiAmcGF0aCl7CiAgICBwYXRoLnB1c2hfYmFjayhub2RlKTsKICAgIGlmKGFkaltub2RlXS5zaXplKCkgPT0gMCAmJiBtcFtub2RlXSA9PSBmYWxzZSl7CiAgICAgICAgbXBbbm9kZV0gPSB0cnVlOwogICAgICAgIGZvcihpbnQgIGkgOiBwYXRoKSBjb3V0IDw8IGkgPDwgIiAiOwogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH1lbHNlewogICAgICAgIGZvcihpbnQgaSA6IGFkaltub2RlXSl7CiAgICAgICAgICAgIHByaW50KGkgLCBwYXRoKTsKICAgICAgICB9CiAgICB9CiAgICBwYXRoLnBvcF9iYWNrKCk7Cn0KCgp2b2lkIHNvbHZlKCl7CiAgICB2ZWN0b3I8aW50PiBwYXRoOwogICAgcHJpbnQoMSAsIHBhdGgpOwp9CgoKaW50IG1haW4oKXsKICAgIGludCBuOyBjaW4gPj4gbjsKICAgIGZvcihpbnQgIGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICBpbnQgYSxiOyBjaW4gPj4gYSA+PiBiOwogICAgICAgIGFkalthXS5wdXNoX2JhY2soYik7CiAgICB9CiAgICBzb2x2ZSgpOwogICAgcmV0dXJuIDA7Cn0=