#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define si(n) scanf("%d",&n)
#define dsi(n) int n; scanf("%d",&n)
#define si2(a,b) scanf("%d%d",&a,&b)
#define dsi2(a,b) int a,b; scanf("%d%d",&a,&b)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define lldout(n) printf("%lld\n",n)
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 2234506;
//int arr[MAX_N];

int main(){
    int TC;
    si(TC);
    while(TC--){
        dsi2(l1,r1);
        dsi2(l2,r2);
        vii V;
        V.PB(ii(l1,r1));
        V.PB(ii(l2,r2));
        SORT(V);
        if(V[0]!=ii(l1,r1))
            printf("%d %d\n",l2,r1);
        else
            printf("%d %d\n",l1,r2);
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define si(n) scanf("%d",&n)
#define dsi(n) int n; scanf("%d",&n)
#define si2(a,b) scanf("%d%d",&a,&b)
#define dsi2(a,b) int a,b; scanf("%d%d",&a,&b)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define lldout(n) printf("%lld\n",n)
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 2234506;
//int arr[MAX_N];

int main(){
    int TC;
    si(TC);
    while(TC--){
        dsi2(l1,r1);
        dsi2(l2,r2);
        vii V;
        V.PB(ii(l1,r1));
        V.PB(ii(l2,r2));
        SORT(V);
        l1=V[0].F;r1=V[0].S;
        l2=V[1].F;r2=V[1].S;
        printf("%d %d\n",l1,r2);
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define si(n) scanf("%d",&n)
#define dsi(n) int n; scanf("%d",&n)
#define si2(a,b) scanf("%d%d",&a,&b)
#define dsi2(a,b) int a,b; scanf("%d%d",&a,&b)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define lldout(n) printf("%lld\n",n)
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 2234506;
//int arr[MAX_N];

int main(){
    int TC;
    si(TC);
    while(TC--){
        dsi2(l1,r1);
        dsi2(l2,r2);
        vii V;
        V.PB(ii(l1,r1));
        V.PB(ii(l2,r2));
        SORT(V);
        if(V[0]!=ii(l1,r1))
            printf("%d %d\n",r2,l1);
        else
            printf("%d %d\n",l1,r2);
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define si(n) scanf("%d",&n)
#define dsi(n) int n; scanf("%d",&n)
#define si2(a,b) scanf("%d%d",&a,&b)
#define dsi2(a,b) int a,b; scanf("%d%d",&a,&b)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define lldout(n) printf("%lld\n",n)
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 2234506;
//int arr[MAX_N];

int main(){
    int TC;
    si(TC);
    while(TC--){
        dsi2(l1,r1);
        dsi2(l2,r2);
        if(l1==l2){
            if(r2!=l1)
                printf("%d %d\n",l1,r2);
            else
                printf("%d %d\n",r1,l2);
        }
        else
            printf("%d %d\n",l1,l2);
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define si(n) scanf("%d",&n)
#define dsi(n) int n; scanf("%d",&n)
#define si2(a,b) scanf("%d%d",&a,&b)
#define dsi2(a,b) int a,b; scanf("%d%d",&a,&b)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define lldout(n) printf("%lld\n",n)
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 2234506;
//int arr[MAX_N];

int main(){
    int TC;
    si(TC);
    while(TC--){
        dsi2(l1,r1);
        dsi2(l2,r2);
        vii V;
        V.PB(ii(l1,r1));
        V.PB(ii(l2,r2));
        SORT(V);
        l1=V[0].F;r1=V[0].S;
        l2=V[0].F;r2=V[0].S;
        printf("%d %d\n",l1,r2);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,l2,l3,l4=0;
        cin>>l1>>r1>>l2>>r2;
        int s=0,e=0;

        if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
        else
            cout<<l2<<" "<<r1<<endl;

       }
       cout<<s<<" "<<e<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,r1,l2,r2=0;
        cin>>l1>>r1>>l2>>r2;

       if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
        else
            cout<<l2<<" "<<r1<<endl;

}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,r1,l2,r2=0;
        cin>>l1>>r1>>l2>>r2;

        if((l1==l2)&&(r1==r2))
            cout<<l1<<" "<<l2<<endl;
        else
        {
            if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
            else
            cout<<l2<<" "<<r1<<endl;
        }
}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,l2,l3,l4=0;
        cin>>l1>>l2>>l3>>l4;

       int a[4];

       a[0]=l1;
       a[1]=l2;
       a[2]=l3;
       a[3]=l4;
       sort(a,a+4);
            cout<<a[0]<<" "<<a[3]<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,l2,l3,l4=0;
        cin>>l1>>l2>>l3>>l4;

        if((l1==l3)&&(l2==l4))
            cout<<l1<<" "<<l2<<endl;
        else
        {
            if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
            else
            cout<<l2<<" "<<r1<<endl;
        }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,l2,r1,r2=0;
        cin>>l1>>r1>>l2>>r2;
        int s=0,e=0;

        if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
        else
            cout<<l2<<" "<<r1<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,r1,l2,r2=0;
        cin>>l1>>r1>>l2>>r2;

        if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
        else
            cout<<l2<<" "<<r1<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,r1,l2,r2=0;
        cin>>l1>>r1>>l2>>r2;
        if(l1!=l2)
        cout<<l1<<" "<<l2<<endl;
        else
        cout<<l1<<" "<<l2+1<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,l2,l3,l4=0;
        cin>>l1>>l2>>l3>>l4;
        int s=0,e=0;
       if(l1>l3)
       {
            s=l3;
            e=l2;
       }
       else
       {
           s=l1;
           e=l4;
       }
       cout<<s<<" "<<e<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,r1,l2,r2=0;
        cin>>l1>>r1>>l2>>r2;
        if((l1==l2)&&(r1==r2))
            cout<<l1<<" "<<r2<<endl;
        else
        {
       if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
        else
            cout<<l2<<" "<<r1<<endl;
        }
}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,r1,l2,r2=0;
        cin>>l1>>r1>>l2>>r2;
        if(l1==l2)&&(r1==r2)
            cout<<l1<<" "<<r2<<endl;
       if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
        else
            cout<<l2<<" "<<r1<<endl;

}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,l2,l3,l4=0;
        cin>>l1>>l2>>l3>>l4;

        if((l1==l2)&&(r1==r2))
            cout<<l1<<" "<<l2<<endl;
        else
        {
            if(l1<=l2)
            cout<<l1<<" "<<r2<<endl;
            else
            cout<<l2<<" "<<r1<<endl;
        }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int l1,l2,l3,l4=0;
        cin>>l1>>l2>>l3>>l4;

        if((l1==l3)&&(l2==l4))
            cout<<l1<<" "<<l2<<endl;
        else
            cout<<l1<<" "<<l4<<endl;
    }
}


#include <iostream>
#include <cstring>
using namespace std;

int main(){
	int n,l1,r1,l2,r2;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l1>>r1>>l2>>r2;
		bool f[r2];
		memset(f,0,sizeof(f));
		if(l2==r2)
			if(l1=l2)
				cout<<l1+1;
			else{
				cout<<l1;
				cout<<' '<<l2<<endl;
			}
		else{
			cout<<l1;
			f[l1-1]=1;
			for(int j=l2;j<r2;j++)
				if(!f[j]){
					cout<<' '<<j+1<<endl;
					break;
				}
		}

	}

	return 0;
}


#include <iostream>
using namespace std;

int main(){
	int n,l1,r1,l2,r2;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l1>>r1>>l2>>r2;
		bool f[r2];
		if(l2==r2)
			if(l1=l2)
				cout<<l1+1;
			else{
				cout<<l1;
				cout<<' '<<l2<<endl;
			}
		else{
			cout<<l1;
			f[l1-1]=1;
			for(int j=l2;j<r2;j++)
				if(!f[j]){
					cout<<' '<<j+1<<endl;
					break;
				}
		}

	}

	return 0;
}


#include <iostream>
#include <cstring>
using namespace std;

int main(){
	int n,l1,r1,l2,r2;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l1>>r1>>l2>>r2;
		bool f[r2];
		memset(f,0,sizeof(f));
		if(l2==r2)
			if(l1=l2 &&)
				cout<<l1+1;
			else{
				cout<<l1;
				cout<<' '<<l2<<endl;
			}
		else{
			cout<<l1;
			f[l1-1]=1;
			for(int j=l2;j<r2;j++)
				if(!f[j]){
					cout<<' '<<j+1<<endl;
					break;
				}
		}

	}

	return 0;
}


#include <iostream>
using namespace std;

int main(){
	int n,l1,r1,l2,r2,j;
	cin>>n;

	for(int i=0;i<n;i++){
		cin>>l1>>r1>>l2>>r2;

		if(l2==r2)
			if(l1=l2)
				cout<<l1+1;
			else{
				cout<<l1;
				cout<<' '<<l2<<endl;
			}
		else{
			cout<<l1;

			j=l2;
			while(j==l1)
				j++;

			cout<<' '<<j<<endl;
		}

	}

	return 0;
}


 #include <iostream>
using namespace std;

int main(){
	int n,l1,r1,l2,r2;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l1>>r1>>l2>>r2;
		bool f[r2];
		memset(f,0,sizeof(f));
		if(l2==r2)
			if(l1=l2)
				cout<<l1+1;
			else{
				cout<<l1;
				cout<<' '<<l2<<endl;
			}
		else{
			cout<<l1;
			f[l1-1]=1;
			for(int j=l2;j<r2;j++)
				if(!f[j]){
					cout<<' '<<j+1<<endl;
					break;
				}
		}

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		double l1,r1,l2,r2;
		scanf("%lf%lf%lf%lf",&l1,&r1,&l2,&r2);
		if(r1 <= l2){
			printf("%.lf %.lf\n",l1+1,l2+1);
			continue;
		}
		if(l1 < l2 && r2 < r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 <= l2 && l2 < r1 && r1 < r2){
			printf("%.lf %.lf\n",l1+1,r2);
			continue;
		}
		if(l1 == l2 && r2 < r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 == l2 && r1 == r2){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		double l1,r1,l2,r2;
		scanf("%lf%lf%lf%lf",&l1,&r1,&l2,&r2);
		if(r1 <= l2){
			printf("%.lf %.lf\n",l1+1,l2+1);
			continue;
		}
		if(l1 < l2 && r2 < r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 <= l2 && l2 < r1 && r1 < r2){
			printf("%.lf %.lf\n",l1+1,r2);
			continue;
		}
		if(l1 == l2 && r2 < r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 == l2 && r1 == r2){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l2 < l1 && l1 < r2 ){
			printf("%.lf %.lf\n",r1,l2);
			continue;
		}

		if(l2 < l1 && r2 < l1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		double l1,r1,l2,r2;
		scanf("%lf%lf%lf%lf",&l1,&r1,&l2,&r2);
		if(r1 <= l2){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}
		if(l1 < l2 && r2 > r1 && l2 < r1){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(l1 <= l2 && r1 <= r2){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

		if(l1 <= l2 && r1 >= r2){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

		if(l1 > l2 && r2 < r1 && r2 >= l1){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(l1 > l2 && r2 <= l1){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		double l1,r1,l2,r2;
		scanf("%lf%lf%lf%lf",&l1,&r1,&l2,&r2);

		if(r1 <= l2){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(l1 <= l2 && r2 > r1 && l2 < r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

		if(l1 > l2 && r2 > r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l2>l1&&l2<r1&&r2<=r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 == l2 && r1 == r2){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l2 < l1 && r2 >l1 && r2 < r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(r2 <= l1){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}
		if(l2 < l1 && r2 >l1 && r2 <= r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		double l1,r1,l2,r2;
		scanf("%lf%lf%lf%lf",&l1,&r1,&l2,&r2);

		if(r1 <= l2){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(l1 < l2 && r2 > r1 && l2 < r1){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}
		if(l1 == l2 && r2 > r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

		if(l1> l2 && r2 > r1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 < l2 && r2 == r1 && l2 < r1){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(l1 < l2 && r2 < r1 && l2 < r1){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(l1 == l2 && r2 < r1 && r2 > l1){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 == l2 && r1 == r2)
		{
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}

		if(l2<l1 && r2> l1 & r2 < r1 )
		{
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(l1 <= l2 && r1 <= r2){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

		if(r2 <= l1){
			printf("%.lf %.lf\n",l2,r1);
			continue;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		double l1,r1,l2,r2;
		scanf("%lf%lf%lf%lf",&l1,&r1,&l2,&r2);
		if(l1 == l2){
			printf("%.lf %.lf\n",l1,r2);
			continue;
		}
		if(l1 != l2){
			printf("%.lf %.lf\n",l1,l2);
			continue;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;
int T,l1,r1,l2,r2;
int main()
{
    cin>>T;
    for(int i=1;i<=T;++i)
    {
        cin>>l1>>r1>>l2>>r2;
        if(l1==r2)
            cout<<l1<<" "<<l2<<endl;
        else
            cout<<l1<<" "<<r2<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[n];
    int l1,l2,r1,r2;
    vector<int> v;
	while(n--) {
		cin>>l1>>r1>>l2>>r2;
        if(l1!=r2){
          v.push_back(l1);
          v.push_back(r2);
        }else{
            v.push_back(l2);
          v.push_back(r1);
        }
	}
    for(int i=0;i<v.size()-1;i+=2){
       cout<<v[i]<<" "<<v[i+1];
       cout<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[n];
    int l1,l2,r1,r2;
    vector<int> v;
	while(n>0) {
		cin>>l1>>r1>>l2>>r2;
        if(l1==l2){
          v.push_back(l1);
          v.push_back(r2);
        }else{
        v.push_back(l1);
        v.push_back(l2);
        }
        n=n-1;
	}
    for(int i=0;i<v.size()-1;i+=2){
       cout<<v[i]<<" "<<v[i+1];
       cout<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
int T,l1,r1,l2,r2;
int main()
{
    cin>>T;
    for(int i=1;i<=T;++i)
    {
        cin>>l1>>r1>>l2>>r2;
        if(l1==r2)
            cout<<l1<<" "<<l2<<endl;
        else
            cout<<l1<<" "<<r2<<endl;
    }


#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[n];
    int l1,l2,r1,r2;
    vector<int> v;
	while(n--) {
		cin>>l1>>r1>>l2>>r2;
        if(l1!=r2){
          v.push_back(l1);
          v.push_back(r2);
        }else{
            v.push_back(l1);
          v.push_back(r1);
        }
	}
    for(int i=0;i<v.size()-1;i+=2){
       cout<<v[i]<<" "<<v[i+1];
       cout<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        for(ll i=l1; i<=r1; i++){
            for(ll j=l2; j<=r2; j++){
                if(i != j) cout<<i<<" "<<j<<"\n";
                break;
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    while(q--){
        ll l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        cout<<l1+1<<" "<<r2-1<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        bool flag = 0;
        cin>>l1>>r1>>l2>>r2;
        for(ll i = l1; i <= r1; i++){
            for(ll j = l2; j <= r2; j++){
                if(i != j) {cout<<i<<" "<<j<<"\n";
                flag=1;
                break;
                }
            }
            if(flag) break;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        bool flag = 0;
        cin>>l1>>r1>>l2>>r2;
        for(ll i=l1; i<=r1; i++){
            for(ll j=l2; j<=r2; j++){
                if(i != j) cout<<i<<" "<<j<<"\n";
                flag=1;
                break;
            }
            if(flag) break;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        for(ll i=l1; i<=r1; i++){
            for(ll j=l2; j<=r2; j++){
                if(i != j) return cout<<i<<" "<<j<<"\n";
                break;
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        if(l1 != r2)
            cout<<l1<<" "<<r2<<"\n";
        else cout<<l2<<" "<<r1<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        cout<<l1<<" "<<r2<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        if(l1 != r2) cout<<l1<<" "<<r2<<"\n";
        else if(l2 != r1) cout<<l2<<" "<<r1<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    ll q;
    cin>>q;
    while(q--){
        ll l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        for(ll i=l1; i<=r1; i++){
            for(ll j=l2; j<=r2; j++){
                if(i != j) return cout<<i<<" "<<j,0;
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

queue<int>v;

int main(){
	int n, c, li, ls, t, cont=0;
	cin>>n;
	for(c=0; c<n; c++){
		cont=0;
		cin>>li;
		cin>>ls;
		cin>>t;
		if(t!=li){
			v.push(t);
			v.push(li);
			cont++;
		}
		cin>>t;
		if(t!=li && cont==0){
			v.push(t);
			v.push(li);
		}
	}
	for(c=0; c<n; c++){
		cout<<v.front()<<" ";
		v.pop();
		cout<<v.front()<<endl;
		v.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

queue<int>v;

int main(){
	int n, c, li, ls, t, cont=0;
	cin>>n;
	for(c=0; c<n; c++){
		cin>>li;
		cin>>ls;
		cin>>t;
		if(t!=li){
			v.push(t);
			v.push(li);
			cont++;
		}
		cin>>t;
		if(t!=li && cont==0){
			v.push(t);
			v.push(li);
		}
	}
	for(c=0; c<n; c++){
		cout<<v.front()<<" ";
		v.pop();
		cout<<v.front()<<endl;
		v.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

queue<int>v;

int main(){
	int n, c, li, ls, t, cont=0;
	cin>>n;
	for(c=0; c<n; c++){
		cont=0;
		cin>>li;
		cin>>ls;
		cin>>t;
		if(t!=li){
			v.push(li);
			v.push(t);
			cont++;
		}
		cin>>t;
		if(t!=li && cont==0){
			v.push(li);
			v.push(t);
		}
	}
	for(c=0; c<n; c++){
		cout<<v.front()<<" ";
		v.pop();
		cout<<v.front()<<endl;
		v.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

queue<int>v;

int main(){
	int n, c, li, ls, t;
	cin>>n;
	for(c=0; c<n; c++){
		cin>>li;
		cin>>ls;
		cin>>t;
		if(t!=li && t!=ls){
			v.push(t);
		}
		cin>>t;
		if(t!=li && t!=ls){
			v.push(t);
		}
	}
	for(c=0; c<n; c++){
		cout<<v.front()<<" ";
		v.pop();
		cout<<v.front()<<endl;
		v.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

queue<int>v;

int main(){
	int n, c, li, ls, t;
	cin>>n;
	for(c=0; c<n; c++){
		cin>>li;
		cin>>ls;
		cin>>t;
		if(t>li){
			li=t;
		}
		cin>>t;
		if(t<ls){
			ls=t;
		}
		v.push(li);
		v.push(ls);
	}
	for(c=0; c<n; c++){
		cout<<v.front()<<" ";
		v.pop();
		cout<<v.front()<<endl;
		v.pop();
	}
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main(){

long q,l1,r1,l2,r2,t;
cin>>q;

vector<long> a,b;

for (int t=0;t<q;t++){
cin>>l1>>r1>>l2>>r2;

if (l1<l2) {
a.push_back(l1);
b.push_back(l2+1);
}else{
    a.push_back(l2);
    b.push_back(l2+1);
}

}

for (int i=0;i<a.size();i++) cout<<a[i]<<" "<<b[i]<<endl;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main(){

long q,l1,r1,l2,r2,t;
cin>>q;

vector<long> a,b;

for (int t=0;t<q;t++){
cin>>l1>>r1>>l2>>r2;

if (l1<l2) {
a.push_back(l1);
b.push_back(l2);
if (a[t]==b[t]) b[t]++;
}else{
    a.push_back(l2);
    b.push_back(l1);
    if (a[t]==b[t]) b[t]++;
}

}

for (int i=0;i<a.size();i++) cout<<a[i]<<" "<<b[i]<<endl;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main(){

long q,l1,r1,l2,r2,t;
cin>>q;

vector<long> a,b;

for (int t=0;t<q;t++){
cin>>l1>>r1>>l2>>r2;
a.push_back(min(l1,l2));
b.push_back(max(r1,r2));
}

for (int i=0;i<a.size();i++) cout<<a[i]<<" "<<b[i]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
    int l1,l2,r1,r2,n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin >> l1 >> r1 >> l2 >> r2;
        int mina = min(l1,l2);
        int maxa = max(r1,r2);
        cout << mina << " " << maxa << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
    int l1,l2,r1,r2,n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin >> l1 >> r1 >> l2 >> r2;
        if(l1 == r2){
            cout << r1 << " " << l2 << endl;
        }else{
            cout << l1 << " " << r2 << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
    int l1,l2,r1,r2,n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin >> l1 >> r1 >> l2 >> r2;
        cout << l1 << " " << r2 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
    int l1,l2,r1,r2,n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin >> l1 >> r1 >> l2 >> r2;
        if((l1 == l2)&&(r1 == r2)){
            cout << l1 << " " << r1 << endl;
        }
        if(l1 < l2){
            cout << l1 << " " << r2 << endl;
        }else{
            cout << r1 << " " << l2 << endl;
        }
    }
    return 0;
}


//By Qingyu qwq!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>

inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read()
{
	int res = 0;
	char ch;
	do ch = nc(); while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res;
}

int main()
{
	int T = read();
	while (T--)
	{
		int l1 = read(), r1 = read(), l2 = read(), r2 = read();
		if (l1 <= l2) printf("%d %d\n", l1, r2);
		else printf("%d %d\n", l1, l2);
	}
	return 0;
}


#include<stdio.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		int l,r,l1,r1;
		scanf("%d%d%d%d",&l,&r,&l1,&r1);
		if(l<=l1)printf("%d %d\n",l,r1);
		else printf("%d %d\n",l1,r);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <set>
using namespace std;
//int map[505][501];
int main()
{
	int num;
	int a,s,d,f;
	cin>>num;
	for(int i=1;i<=num;i++)
	{
		cin>>a>>s>>d>>f;
		if(a!=d)
		cout<<a<<" "<<d<<endl;
		else
		cout<<a<<" "<<f<<endl;
	}
	return 0;
 }


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> vi;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()

string problem_name = "a";

void init(){
  freopen((problem_name+".in").c_str(),"rt",stdin);
 // freopen((problem_name+".out").c_str(),"wt",stdout);
}

map <int, pair <int,int>  > m;
vector <pair <int,int > > t;
int main()
{
 //  init();

//	printf("2 100 1 ");
//	return 0;

	int n;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		t.push_back(make_pair(a,b));
		if (m[a].first==0) m[a].first=b; else
			m[a].second = b;

		if (m[b].first==0) m[b].first=a; else
			m[b].second = a;
	}

	int cur=0;
	for (int i=0;i<sz(t);i++) {
		if (m[t[i].first].second == 0) cur=t[i].first;
		if (m[t[i].second].second == 0) cur=t[i].second;
	}

	int pred=-1;
	printf("%d ",cur);
	for (int i=0;i<n;i++)
	{
		int a=cur;
		if (m[cur].first!=pred) cur = m[cur].first; else
			cur = m[cur].second;

		printf("%d ",cur);
		pred=a;

	}

  return 0;
}


//============================================================================
// Name        : C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define MAXN 100005

int N,c1,c2,deg[MAXN],way[MAXN][2],cnt[MAXN],mind;
map<int,int> m,mm;
bool visited[MAXN][2];
stack<int> sta;

void DFS(int now)
{
	int i;
	for(i = 0; i <= cnt[now]; ++i)
	{
		if(!visited[now][i])
		{
			visited[now][i] = true;
			if(way[way[now][i]][0] == now)
				visited[way[now][i]][0] = true;
			else
				visited[way[now][i]][1] = true;
			DFS(way[now][i]);
		}
	}
	sta.push(now);
}

int main() {
	int i;
	bool flag;
	while(scanf("%d", &N) == 1)
	{
		m.clear();
		mm.clear();
		memset(cnt,-1,sizeof(cnt));
		memset(deg,0,sizeof(deg));
		memset(way,0,sizeof(way));
		mind = 0;
		memset(visited,false,sizeof(visited));

		for(i = 1; i <= N; ++i)
		{
			scanf("%d%d", &c1, &c2);
			if(m.find(c1) == m.end())
			{
				m[c1] = ++mind;
				mm[mind] = c1;
			}
			if(m.find(c2) == m.end())
			{
				m[c2] = ++mind;
				mm[mind] = c2;
			}
			way[m[c1]][++cnt[m[c1]]] = m[c2];
			way[m[c2]][++cnt[m[c2]]] = m[c1];
			++deg[m[c1]];
			++deg[m[c2]];
		}

		for(i = mind; i >= 1; --i)
			if(deg[i] == 1)
				break;

		if(i == 0)
			DFS(mind);

		flag = false;
		while(!sta.empty())
		{
//			printf("%d ", mm[sta.top()]);
			if(!flag)
			{
				printf("%d", mm[sta.top()]);
				flag = true;
			}
			else
				printf(" %d", mm[sta.top()]);

			sta.pop();
		}
		putchar('\n');
	}
	return 0;
}


//============================================================================
// Name        : C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define MAXN 100005

int N,c1,c2,deg[MAXN],way[MAXN][2],cnt[MAXN],mind;
map<int,int> m,mm;
bool visited[MAXN][2];
stack<int> sta;

void DFS(int now)
{
	int i;
	for(i = 0; i <= cnt[now]; ++i)
	{
		if(!visited[now][way[now][i]])
		{
			visited[now][way[now][i]] = true;
			visited[way[now][i]][now] = true;
			DFS(way[now][i]);
		}
	}
	sta.push(now);
}

int main() {
	int i;
	bool flag;
	while(scanf("%d", &N) == 1)
	{
		m.clear();
		mm.clear();
		memset(cnt,-1,sizeof(cnt));
		memset(deg,0,sizeof(deg));
		memset(way,0,sizeof(way));
		mind = 0;
		memset(visited,false,sizeof(visited));

		for(i = 1; i <= N; ++i)
		{
			scanf("%d%d", &c1, &c2);
			if(m.find(c1) == m.end())
			{
				m[c1] = ++mind;
				mm[mind] = c1;
			}
			if(m.find(c2) == m.end())
			{
				m[c2] = ++mind;
				mm[mind] = c2;
			}
			way[m[c1]][++cnt[m[c1]]] = m[c2];
			way[m[c2]][++cnt[m[c2]]] = m[c1];
			++deg[m[c1]];
			++deg[m[c2]];
		}

		for(i = mind; i >= 1; --i)
			if(deg[i] == 1)
				break;

		DFS(i);

		flag = false;
		while(!sta.empty())
		{
			if(!flag)
			{
				printf("%d", mm[sta.top()]);
				flag = true;
			}
			else
				printf(" %d", mm[sta.top()]);

			sta.pop();
		}
		putchar('\n');
	}
	return 0;
}


//============================================================================
// Name        : C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define MAXN 100005

int N,c1,c2,deg[MAXN],way[MAXN][2],cnt[MAXN],mind;
map<int,int> m,mm;
bool visited[MAXN][2];
stack<int> sta;

void DFS(int now)
{
	int i;
	for(i = 0; i <= cnt[now]; ++i)
	{
		if(!visited[now][way[now][i]])
		{
			visited[now][way[now][i]] = true;
			visited[way[now][i]][now] = true;
			DFS(way[now][i]);
		}
	}
	sta.push(now);
}

int main() {
	int i;
//	bool flag;
	while(scanf("%d", &N) == 1)
	{
		m.clear();
		mm.clear();
		memset(cnt,-1,sizeof(cnt));
		memset(deg,0,sizeof(deg));
		memset(way,0,sizeof(way));
		mind = 0;
		memset(visited,false,sizeof(visited));

		for(i = 1; i <= N; ++i)
		{
			scanf("%d%d", &c1, &c2);
			if(m.find(c1) == m.end())
			{
				m[c1] = ++mind;
				mm[mind] = c1;
			}
			if(m.find(c2) == m.end())
			{
				m[c2] = ++mind;
				mm[mind] = c2;
			}
			way[m[c1]][++cnt[m[c1]]] = m[c2];
			way[m[c2]][++cnt[m[c2]]] = m[c1];
			++deg[m[c1]];
			++deg[m[c2]];
		}

		for(i = mind; i >= 1; --i)
			if(deg[i] == 1)
				break;

		DFS(i);

//		flag = false;
		while(!sta.empty())
		{
			printf("%d ", mm[sta.top()]);
/*			if(!flag)
			{
				printf("%d", mm[sta.top()]);
				flag = true;
			}
			else
				printf(" %d", mm[sta.top()]);
*/
			sta.pop();
		}
		putchar('\n');
	}
	return 0;
}


//============================================================================
// Name        : C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define MAXN 100005

int N,c1,c2,deg[MAXN],way[MAXN][2],cnt[MAXN],mind;
map<int,int> m,mm;
bool visited[MAXN][2];
stack<int> sta;

void DFS(int now)
{
	int i;
	for(i = 0; i <= cnt[now]; ++i)
	{
		if(!visited[now][i])
		{
			visited[now][i] = true;
			if(way[way[now][i]][0] == now)
				visited[way[now][i]][0] = true;
			else
				visited[way[now][i]][1] = true;
			DFS(way[now][i]);
		}
	}
	sta.push(now);
}

int main() {
	int i;
	bool flag;
	while(scanf("%d", &N) == 1)
	{
		m.clear();
		mm.clear();
		memset(cnt,-1,sizeof(cnt));
		memset(deg,0,sizeof(deg));
		memset(way,0,sizeof(way));
		mind = 0;
		memset(visited,false,sizeof(visited));

		for(i = 1; i <= N; ++i)
		{
			scanf("%d%d", &c1, &c2);
			if(m.find(c1) == m.end())
			{
				m[c1] = ++mind;
				mm[mind] = c1;
			}
			if(m.find(c2) == m.end())
			{
				m[c2] = ++mind;
				mm[mind] = c2;
			}
			way[m[c1]][++cnt[m[c1]]] = m[c2];
			way[m[c2]][++cnt[m[c2]]] = m[c1];
			++deg[m[c1]];
			++deg[m[c2]];
		}

		for(i = mind; i >= 1; --i)
			if(deg[i] == 1)
				break;

		if(i == 0)
			DFS(mind);
		else
			DFS(i);

		flag = false;
		while(!sta.empty())
		{
//			printf("%d ", mm[sta.top()]);
			if(!flag)
			{
				printf("%d", mm[sta.top()]);
				flag = true;
			}
			else
				printf(" %d", mm[sta.top()]);

			sta.pop();
		}
		putchar('\n');
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <random>
#include <utility>
#include <stdlib.h>
#include <iomanip>
#include <map>

#define loop(i,s,e) for(int i = s;i<e;i++)

using namespace std;

const int N = (int)10e5 + 1;

map<int, pair<int, vector<int>>> graph;

int main()
{
	int n;
	cin >> n;

	while (n--)
	{
		int from, to;
		cin >> from >> to;

		if (graph.count(from) == 0)
		{
			graph[from].first = 0;
		}

		if (graph.count(to) == 0)
		{
			graph[to].first = 0;
		}

		graph[from].second.insert(graph[from].second.begin(), to);
		graph[from].first++;

		graph[to].second.insert(graph[to].second.begin(), from);
		graph[to].first++;
	}

	int from = 0, to = 0;
	for (auto iterator = graph.begin(); iterator != graph.end(); iterator++)
	{
		if (iterator->second.first == 1)
		{
			if (from == 0)
			{
				from = iterator->first;
			}
			else
			{
				to = iterator->first;
			}
		}
	}

	cout << from << " ";

	int curent = from;
	while (curent != to)
	{
		vector<int> linked = graph[curent].second;
		int next = 0;
		for (auto iterator = linked.begin(); iterator != linked.end(); iterator++)
		{
			if (graph.count(*iterator) > 0)
			{
				next = *iterator;
				break;
			}
		}

		graph.erase(graph.find(curent));

		curent = next;
		cout << curent << " ";
	}

	return 0;
}


// ==========================================================================
//  A.cpp
// ==========================================================================

#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

#if defined _UVA_PROJECT
#  include "UVa Problem.h"
#  define _NAMESPACE	_CF_PROBLEM_29_C
#else // _UVA_PROJECT
#  define _BEGIN_PROBLEM(id)
#  define _END_PROBLEM
#  define infinite_loop	for (;;)
#endif // !_UVA_PROJECT

_BEGIN_PROBLEM(CF 29 C)

int degree[100001], next[100001], next2[100001], id[100001];

int main(
	) {
		map<int, int> m;

		int n;
		scanf("%d", &n);

		int N = 1;

		for (int i = 0, ju, jv; i < n; ++i) {
			scanf("%d %d", &ju, &jv);
			int & _u = m[ju], & _v = m[jv];
			if (_u == 0) _u = N++, id[_u] = ju;
			if (_v == 0) _v = N++, id[_v] = jv;
			if (next[_u]) next2[_u] = _v; else next[_u] = _v;
			if (next[_v]) next2[_v] = _u; else next[_v] = _u;
			++degree[_u], ++degree[_v];
		}

		int u = 1, v;
		while (degree[u] != 1) ++u;
		v = next[u];

		for (int i = 0; i < n; ++i) {
			printf("%d ", id[u]);

			int c = next[v];
			if (c == u) c = next2[v];

			u = v, v = c;
		}

		printf("%d\n", id[u]);

		return 0;
	}

_END_PROBLEM

// ==========================================================================
//  End of file.
// ==========================================================================


#include <iostream>
#include <vector>
#include <map>
using namespace std;
int n,a,b;
map <int,vector <int> > c;
int main()
{
	cin >> n;
	for (int i=0;i<n;i++)
	{
		cin >> a >> b;
		c[a].push_back(b);
		c[b].push_back(a);
	}
	while (c[b].size()==2)
	{
		if (a==c[b][0])
		{
			a=b;
			b=c[b][1];
		}
		else
		{
			a=b;
			b=c[b][0];
		}
	}
	cout << b;
	while (c[a].size()==2)
	{
		if (b==c[a][0])
		{
			b=a;
			a=c[a][1];
		}
		else
		{
			b=a;
			a=c[a][0];
		}
		cout << " " << b;
	}
	cout << " " << a;
	return 0;
}


#include <stdio.h>
#include <set>
#include <map>
using namespace std;
map<int,int> d,next,prev;
int list[11111],hl;
int main(){
	int n,x,y,i,p;
	while (scanf("%d",&n)>0 && n){
		d.clear();
		next.clear();
		prev.clear();
		hl=0;
		for (i=0;i<n;i++){
			scanf("%d%d",&x,&y);
			if (d.find(x)==d.end())
				list[hl++]=x;
			d[x]++;
			if (d.find(y)==d.end())
				list[hl++]=y;
			d[y]++;
			if (next.find(x)==next.end())
				next[x]=y;
			else
				prev[x]=y;
			if (next.find(y)==next.end())
				next[y]=x;
			else
				prev[y]=x;
		}
		for (i=0;i<hl;i++)
			if (d[list[i]]==1)
				break;
		printf("%d ",list[i]);
		p=list[i];
		x=next[list[i]];
		while (d[x]!=1){
			printf("%d ",x);
			if (next[x]!=p){
				p=x;
				x=next[x];
			}
			else{
				p=x;
				x=prev[x];
			}
		}
		printf("%d\n",x);
	}

	return 0;
}


#include <stdio.h>
#include <map>
using namespace std;
map<int,int> d,next,prev;
int list[100111],hl;
int main(){
	int n,x,y,i,p;
	while (scanf("%d",&n)>0 && n){
		d.clear();
		next.clear();
		prev.clear();
		hl=0;
		for (i=0;i<n;i++){
			scanf("%d%d",&x,&y);
			if (d.find(x)==d.end())
				list[hl++]=x;
			d[x]++;
			if (d.find(y)==d.end())
				list[hl++]=y;
			d[y]++;
			if (next.find(x)==next.end())
				next[x]=y;
			else
				prev[x]=y;
			if (next.find(y)==next.end())
				next[y]=x;
			else
				prev[y]=x;
		}
		for (i=0;i<hl;i++)
			if (d[list[i]]==1)
				break;
		printf("%d ",list[i]);
		p=list[i];
		x=next[list[i]];
		while (d[x]!=1){
			printf("%d ",x);
			if (next[x]!=p){
				p=x;
				x=next[x];
			}
			else{
				p=x;
				x=prev[x];
			}
		}
		printf("%d\n",x);
	}
	return 0;
}


// cf29c
#include <iostream>
#include <map>
using namespace std;

int links[100002][2]={0},reverse[100002];
map<int,int> lookup;

int main()
{
  int n,used=0,index1,index2,c1,c2,from,to,curr;

#ifndef ONLINE_JUDGE
  FILE *stream;
  freopen_s(&stream,"testfile","r",stdin);
#endif
  cin >> n;
  for(curr=0;curr<n;curr++){
    cin >> c1 >> c2;
    index1=lookup[c1];
    if(index1==0){
      index1=++used;
      lookup[c1]=used;
      reverse[used]=c1;
    }
    index2=lookup[c2];
    if(index2==0){
      index2=++used;
      lookup[c2]=used;
      reverse[used]=c2;
    }
    if(links[index1][0]==0) links[index1][0]=index2;
    else links[index1][1]=index2;
    if(links[index2][0]==0) links[index2][0]=index1;
    else links[index2][1]=index1;
  }
  for(curr=1;curr<=used;curr++) if(links[curr][1]==0) break;
  cout << reverse[curr] << ' ';
  to=links[curr][0];
  while(to){
    cout << reverse[to] << ' ';
    from=curr;
    curr=to;
    if(links[curr][0]==from) to=links[curr][1];
    else to=links[curr][0];
  }
  cout << '\n';
  return 0;
}


#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <list>
#include <ctime>
#include <float.h>
#include <memory.h>

using namespace std;

#define REP(i, from, to) for (int i = (from); i < (to); ++i)
#define FOR(i, n) REP(i, 0, (n))
#define ALL(x) x.begin(), x.end()
#define SIZE(x) (int)x.size()
#define PB push_back
#define MP make_pair

typedef long long i64;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef pair<int, int> PII;

int main() {
  //freopen("input.txt", "r", stdin);
  int n;
  cin >> n;

  map<int, int> degree;
  map<int, stack<int> > adj;
  FOR (i, n) {
    int a, b;
    cin >> a >> b ;
    --a; --b;
    adj[a].push(b);
    adj[b].push(a);

    ++degree[a];
    ++degree[b];
  }

  int start = -1;
  map<int, int>::const_iterator it = degree.begin();
  while (it != degree.end()) {
    if (it->second == 1) {
      start = it->first;
      break;
    }

    ++it;
  }

  set<int> used;
  cout << start + 1;
  while (true) {
    if (adj[start].empty()) break;
    int next = adj[start].top();
    adj[start].pop();
    if (used.count(next)) continue;
    start = next;
    used.insert(start);
    cout << " " << start + 1;
  }

  cout << "\n";

  return 0;
}


#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <list>
#include <ctime>
#include <float.h>
#include <memory.h>

using namespace std;

#define REP(i, from, to) for (int i = (from); i < (to); ++i)
#define FOR(i, n) REP(i, 0, (n))
#define ALL(x) x.begin(), x.end()
#define SIZE(x) (int)x.size()
#define PB push_back
#define MP make_pair

typedef long long i64;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef pair<int, int> PII;

int main() {
  //freopen("input.txt", "r", stdin);
  int n;
  cin >> n;

  map<int, int> degree;
  map<int, stack<int> > adj;
  FOR (i, n) {
    int a, b;
    cin >> a >> b ;
    --a; --b;
    adj[a].push(b);
    adj[b].push(a);

    ++degree[a];
    ++degree[b];
  }

  int start = -1;
  map<int, int>::const_iterator it = degree.begin();
  while (it != degree.end()) {
    if (it->second == 1) {
      start = it->first;
      break;
    }

    ++it;
  }

  set<int> used;
  cout << start + 1;
  used.insert(start);
  while (true) {
    if (adj[start].empty()) break;
    int next = adj[start].top();
    adj[start].pop();
    if (used.count(next)) continue;
    start = next;
    used.insert(start);
    cout << " " << start + 1;
  }

  cout << "\n";

  return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
using namespace std;
void dfs(map<int, vector<int>> &G, map<int, bool> &used, int v)
{
	used[v] = true;
	cout << v << " ";
	for (size_t i = 0; i < G[v].size(); ++i)
	{
		int to = G[v][i];
		if (!used[to])
			dfs(G, used, to);
	}
}
int main()
{
	map<int, vector<int>> G;
	map<int, vector<int>>::iterator it;
	map<int, bool> used;
	int n, i, x, y ,v;
	cin >> n;
	for (i = 0; i < n; ++i)
	{
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for (it = G.begin(); it != G.end(); ++it)
	{
		if (it->second.size() == 1)
		{
			v = it->first;
			break;
		}
	}
	dfs(G, used, v);
	cout << endl;
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main()
{
    vector <int> v;
    map <int,vector <int> > a;
    int n,g,q,i,t,pri;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&g,&q);
        if(!a[g].size())
            v.push_back(g);
        if(!a[q].size())
            v.push_back(q);
        a[g].push_back(q);
        a[q].push_back(g);

    }
    for(i=0;i<=v.size()-1;i++)
        if(a[v[i]].size()==1)
        {
            t=a[v[i]][0];
            pri=v[i];
            printf("%d",pri);
            break;
        }
    bool flag=true;
    while(flag)
    {
        if(a[t].size()>1)
        {
            if(a[t][0]==pri)
            {
                pri=t;
                t=a[t][1];
            }
            else
            {
                pri=t;
                t=a[t][0];
            }
            printf(" %d",pri);
        }
        else
        {
            flag=false;
            printf(" %d\n",t);
        }
    }

    return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

LL GCD ( LL a, LL b ) { return b != 0 ? GCD(b, a % b) : a; }
LL LCM ( LL a, LL b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

map< int, PII > m;

void DFS ( int id, int prev )
{
    printf( " %d", id );

    if ( m[ id ].Y == 0 ) return;

    if ( m[ id ].X == prev ) DFS( m[ id ].Y, id );
    else DFS( m[ id ].X, id );
}

int main ()
{
    int N;
    scanf( "%d", &N );
    REP(i,N)
    {
        int a, b;
        scanf( "%d %d", &a, &b );
        if ( m[ a ].X != 0 )
            m[ a ].Y = b;
        else
            m[ a ].X = b;

        if ( m[ b ].X != 0 )
            m[ b ].Y = a;
        else
            m[ b ].X = a;
    }

    auto iter = m.begin();
    while ( iter != m.end() )
    {
        if ( iter->Y.Y == 0 )
        {
            printf( "%d", iter->X );
            DFS( iter->Y.X, iter->X );
            printf( "\n" );
            break;
        }

        ++iter;
    }

    return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

void flery(int &v, vector<vector<int>> &a, vector<int> &ans)
{
	while (a[v].size() != 0)
	{
		int w = a[v][a[v].size() - 1];
		a[v].erase(a[v].begin() + a[v].size() - 1);
		for (int i = 0; i < a[w].size(); ++i)
		{
			if (a[w][i] == v)
				a[w].erase(a[w].begin() + i);
		}
		flery(w, a, ans);
	}
	ans.push_back(v);
}
void main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int m;
	cin >> m;
	set<pair<long long, long long>> vec;
	vector<int> ans;
	long long max_el = -LLONG_MAX;
	set<int> ger;
	for (int i = 0; i < m; ++i)
	{
		long long ch1, ch2;
		cin >> ch1 >> ch2;
		ch1--, ch2--;
		ger.insert(ch1); ger.insert(ch2);
		vec.insert(make_pair(ch1, ch2));
		if (ch1 > max_el)
			max_el = ch1;
		if (ch2 > max_el)
			max_el = ch2;
	}
	map<long long, int> dict;
	map<int, long long> dict1;
	int ind = 0;
	for (auto i = vec.begin(); i != vec.end(); ++i)
	{
		if(dict.find(i->first) == dict.end())
			dict.insert(make_pair(i->first, ind++));
		if (dict.find(i->second) == dict.end())
			dict.insert(make_pair(i->second, ind++));
	}
	for (auto i = dict.begin(); i != dict.end(); ++i)
		dict1.insert(make_pair(i->second, i->first));
	vector<vector<int>> a (ger.size());
	for (auto i = vec.begin(); i != vec.end(); ++i)
	{
		a[dict[i->first]].push_back(dict[i->second]);
		a[dict[i->second]].push_back(dict[i->first]);
	}
	int start;
	for (int i = 0; i < a.size(); ++i)
		if (a[i].size() == 1)
		{
			start = i;
			break;
		}
	flery(start, a, ans);
	for (int i = 0; i < ans.size(); ++i)
		cout << ++dict1[ans[i]] << " ";
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <set>

using namespace std;

void flery(int &v, vector<vector<int>> &a, vector<int> &ans)
{
	while (a[v].size() != 0)
	{
		int w = a[v][a[v].size() - 1];
		a[v].erase(a[v].begin() + a[v].size() - 1);
		for (int i = 0; i < a[w].size(); ++i)
		{
			if (a[w][i] == v)
				a[w].erase(a[w].begin() + i);
		}
		flery(w, a, ans);
	}
	ans.push_back(v + 1);
}
void main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int m;
	cin >> m;
	vector<pair<int, int>> vec;
	vector<int> ans;
	int max_el = -INT_MAX;
	for (int i = 0; i < m; ++i)
	{
		int ch1, ch2;
		cin >> ch1 >> ch2;
		ch1--, ch2--;
		vec.push_back(make_pair(ch1, ch2));
		if (ch1 > max_el)
			max_el = ch1;
		if (ch2 > max_el)
			max_el = ch2;
	}
	vector<vector<int>> a (max_el + 1);
	for (int i = 0; i < m; ++i)
	{
		a[vec[i].first].push_back(vec[i].second);
		a[vec[i].second].push_back(vec[i].first);
	}
	int start;
	for (int i = 0; i < a.size(); ++i)
		if (a[i].size() == 1)
		{
			start = i;
			break;
		}
	flery(start, a, ans);
	for (int i = 0; i < ans.size(); ++i)
		cout << ans[i] << " ";
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
//#include <set>

using namespace std;
void dfs(int &v, vector<vector<int>> &a, vector<int> &p)
{
	for (int i = 0; i < a[v].size(); ++i)
	{
		if (p[a[v][i]] == -1)
		{
			p[a[v][i]] = v;
			dfs(a[v][i], a, p);
		}
	}
}
void main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, r1, r2;
	cin >> n >> r1 >> r2;
	r1--, r2--;
	vector<vector<int>> a(n);
	vector<pair<int, int>> vec;
	vector<int> p(n), p1(n, -1);
	p1[r2] = r2;
	for (int i = 0; i < n; ++i)
	{
		if (i == r1)
			p[i] = r1;
		else
		{
			cin >> p[i];
			p[i]--;
		}
	}
	for(int i = 0; i < n; ++i)
	{
		if(i != r1)
			vec.push_back(make_pair(i, p[i]));
	}
	for (int i = 0; i < n - 1; ++i)
	{
		if (vec[i].first != vec[i].second)
		{
			a[vec[i].first].push_back(vec[i].second);
			a[vec[i].second].push_back(vec[i].first);
		}
	}
	dfs(r2, a, p1);
	for (int i = 0; i < n; ++i)
		if (i != r2)
			cout << ++p1[i] << " ";
}


#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;
ifstream fin("document.in");
ofstream fout("document.out");
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
long long gcd( long long x, long long y )
{
   if( x < y )
      return gcd( y, x );

   long long f = x % y;
   if( f == 0 )
     return y;
   else
      return gcd( y, f );
}
long long atoll(string x)
{
long long c=0;
for(int i=0;i<x.size();i++){c*=10;c+=x[i]-'0';}
return c;
}
void ff(){
vector<long long>::iterator lw;
vector<long long >vec;
long long n;
	lw=lower_bound(vec.begin(),vec.end(),n);
	int indx=(lw- vec.begin());
	cout << vec[indx] << '\n';
}
map <int, bool> used;
map <int, vector <int> > mp;
void dfs (int v)
{
    if (used[v])
        return;
    cout << v << " ";
    used[v] = true;

    for (int i = 0; i < mp[v].size(); ++i)
    {
        dfs(mp[v][i]);
    }
}
int main()
{

    int n;
    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }

    for (map <int, vector <int> >::iterator it = mp.begin(); it != mp.end(); ++it) {
        if (it->second.size() == 1) {
            dfs(it->first);
            return 0;
        }
    }

    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;
map <int, bool> used;
map <int, vector <int> > mp;
void dfs (int v)
{
    if (used[v])
        return;
    cout << v << " ";
    used[v] = true;

    for (int i = 0; i < mp[v].size(); ++i)
    {
        dfs(mp[v][i]);
    }
}
int main()
{

    int n;
    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }

    for (map <int, vector <int> >::iterator it = mp.begin(); it != mp.end(); ++it) {
        if (it->second.size() == 1) {
            dfs(it->first);
            return 0;
        }
    }

    return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS

#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int INF = 1000 * 1000 * 1000;

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) v.begin(), v.end()
#define SZ(v) (int) v.size()
#define SQR(x) ((x) * (x))
#define MP make_pair

#define prev SashaGrey

vector<vector<int> > g;

map<int, int> inv;

void dfs(int v, int prev = -1) {
    printf("%d ", inv[v]);
    REP(i, 0, SZ(g[v])) {
        int to = g[v][i];
        if (to != prev) {
            dfs(to, v);
        }
    }
}

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int N;

    scanf("%d", &N);

    map<int, int> compressor;

    vector<pii> e;

    REP(i, 0, N) {
        int u, v;
        scanf("%d%d", &u, &v);
        compressor.insert(MP(u, 0));
        compressor.insert(MP(v, 0));
        e.push_back(MP(u, v));
    }

    int q = 0;

    for(map<int, int>::iterator it = compressor.begin(); it != compressor.end(); ++it) {
        it->second = q++;
        inv.insert(MP(it->second, it->first));
    }

    g.resize(q);

    REP(i, 0, N) {
        g[compressor[e[i].first]].push_back(compressor[e[i].second]);
        g[compressor[e[i].second]].push_back(compressor[e[i].first]);
    }

    REP(i, 0, q)
        if (SZ(g[i]) == 1) {
            dfs(i);
            return 0;
        }

    return 0;
}


#include <stdio.h>
#include <map>

#define SZ 100005
#define WHITE 0
#define BLACK 1

using namespace std;

map < int, int > city;

int g[SZ][5], len[SZ], color[SZ], node[SZ];

void dfs( int u )
{
	int i, v, r;

	color[u] = BLACK;

	for( i = 1; i <= len[u]; i++ )
	{
		v = g[u][i];
		if( color[v] == WHITE )
		{
			printf( "%d ", node[v] );
			dfs( v );
		}
	}
}

int main()
{
	int i, n, u, v, U, V, k;

	freopen("input.txt", "r", stdin );

	while( scanf( "%d", &n ) == 1 )
	{
		city.clear();

		memset(len, 0, sizeof(len));
		memset(node, 0, sizeof(node));
		memset(color, 0, sizeof(color));
		memset(g, 0, sizeof(g));

		for( i = 1, k = 1; i <= n; i++ )
		{
			scanf( "%d%d", &U, &V ) ;

			if( city.find(U) != city.end())
				u = city[U];
			else
				u = city[U] = k++;

			node[u] = U;

			if( city.find(V) != city.end())
				v = city[V];
			else
				v = city[V] = k++;

			node[v] = V;

			g[u][++len[u]] = v;
			g[v][++len[v]] = u;
		}

		for( i = 1; i <= n; i++ )
		{
			if( len[i] == 1 ) break;
		}

		printf( "%d ", node[i] );

		dfs( i );

		printf( "\n" ) ;
	}

	return 0;
}


#include <stdio.h>
#include <map>

#define SZ 100005
#define WHITE 0
#define BLACK 1

using namespace std;

map < int, int > city;

int g[SZ][5], len[SZ], color[SZ], node[SZ];

void dfs( int u )
{
	int i, v, r;

	color[u] = BLACK;

	for( i = 1; i <= len[u]; i++ )
	{
		v = g[u][i];
		if( color[v] == WHITE )
		{
			printf( " %d", node[v] );
			dfs( v );
		}
	}
}

int main()
{
	int i, n, u, v, U, V, k;

	freopen("input.txt", "r", stdin );

	while( scanf( "%d", &n ) == 1 )
	{
		city.clear();

		memset(len, 0, sizeof(len));
		memset(node, 0, sizeof(node));
		memset(color, 0, sizeof(color));
		memset(g, 0, sizeof(g));

		for( i = 1, k = 1; i <= n; i++ )
		{
			scanf( "%d%d", &U, &V ) ;

			if( city.find(U) != city.end())
				u = city[U];
			else
				u = city[U] = k++;

			node[u] = U;

			if( city.find(V) != city.end())
				v = city[V];
			else
				v = city[V] = k++;

			node[v] = V;

			g[u][++len[u]] = v;
			g[v][++len[v]] = u;
		}

		for( i = 1; i <= n; i++ )
		{
			if( len[i] == 1 ) break;
		}

		printf( "%d", node[i] );

		dfs( i );

		printf( "\n" ) ;
	}

	return 0;
}


#include <stdio.h>
#include <map>

#define SZ 100005
#define WHITE 0
#define BLACK 1

using namespace std;

map < int, int > city;

int g[SZ][5], len[SZ], color[SZ], node[SZ];

void dfs( int u )
{
	int i, v, r;

	color[u] = BLACK;

	for( i = 1; i <= len[u]; i++ )
	{
		v = g[u][i];
		if( color[v] == WHITE )
		{
			printf( " %d", node[v] );
			dfs( v );
		}
	}
}

int main()
{
	int i, n, u, v, U, V, k;

	//freopen("input.txt", "r", stdin );

	while( scanf( "%d", &n ) == 1 )
	{
		city.clear();

		memset(len, 0, sizeof(len));
		memset(node, 0, sizeof(node));
		memset(color, 0, sizeof(color));
		memset(g, 0, sizeof(g));

		for( i = 1, k = 1; i <= n; i++ )
		{
			scanf( "%d%d", &U, &V ) ;

			if( city.find(U) != city.end())
				u = city[U];
			else
				u = city[U] = k++;

			node[u] = U;

			if( city.find(V) != city.end())
				v = city[V];
			else
				v = city[V] = k++;

			node[v] = V;

			g[u][++len[u]] = v;
			g[v][++len[v]] = u;
		}

		for( i = 1; i <= n; i++ )
		{
			if( len[i] == 1 ) break;
		}

		printf( "%d", node[i] );

		dfs( i );

		printf( "\n" ) ;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define SZ(x)((int)(x).size())

map<int,vector<int> > e;
map<int,bool> vis;

int main()
{
	int n,a,b;

	cin>>n;
	while (n--)
	{
		cin>>a>>b;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	int p=0;
	for(map<int,vector<int> > :: iterator it=e.begin();it!=e.end();it++)
	if (SZ(it->second)==1) p=it->first;

	do
	{
		vis[p]=1;
		cout<<p<<" ";
		if (vis[e[p][0]]) p=e[p][1]; else p=e[p][0];
	}while (SZ(e[p])==2);
	cout<<p;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define mp make_pair
typedef long long ll;
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair <pair <int, int>, pair <int, int> > pairpair;
ll K=1;

vector <vector <int > > v;
map <int, int> c;
vector <int> x;

int main()
{
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	int n, a, b, i, k=0;
	cin>>n;
	x.resize(100010);
	for (i=0; i<n; i++)
	{
		cin>>a>>b;
		if (!c.count(a))
		{
			v.push_back(vector <int>());
			c[a]=k;
			x[k]=a;
			k++;
		}
		if (!c.count(b))
		{
			v.push_back(vector <int>());
			c[b]=k;
			x[k]=b;
			k++;
		}
		v[c[a]].push_back(c[b]);
		v[c[b]].push_back(c[a]);
	}
	i=0;
	while (v[i].size()!=1) i++;
	cout<<x[i]<<' ';
	a=i;
	b=v[i][0];
	while(1)
	{
		cout<<x[b]<<' ';
		if (v[b].size()==1) break;
		i=b;
		if (v[b][0]==a) b=v[b][1];
		else b=v[b][0];
		a=i;
	}

	return 0;
}


#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;

int main(){
	map<int,int> ind2num,num2ind;
	vector<vector<int> > next(100002);
	int n,a,b,ind=1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(!num2ind[a]){num2ind[a]=ind++;ind2num[num2ind[a]]=a;}
		if(!num2ind[b]){num2ind[b]=ind++;ind2num[num2ind[b]]=b;}
		next[num2ind[a]].push_back(num2ind[b]);
		next[num2ind[b]].push_back(num2ind[a]);
	}

	int st;
	for(int i=0;i<n+1;i++)
		if(next[i].size()==1){st=i;break;}
	cout<<ind2num[st];
	int bef=st,cnt=0;
	for(int i=st;cnt<n;){
		for(int j=0;j<next[i].size();j++){
			if(next[i][j]!=bef){
				bef=i;i=next[i][j];
				cout<<" "<<ind2num[i];
				cnt++;
				break;
			}
		}
	}
	return 0;
}

/*
int main(){
	set<pair<long long,long long> > stamp;
	set<long long> mark;
	set<long long>::iterator it;
	long long n,a,b;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		stamp.insert(make_pair(a,b));

		it=mark.find(a);
		if(it==mark.end())mark.insert(a);
		else	mark.erase(it);

		it=mark.find(b);
		if(it==mark.end())mark.insert(b);
		else	mark.erase(it);
	}

	vector<long long> ans;
	ans.push_back(*mark.begin());
	set<pair<long long,long long> >::iterator sit;
	for(int i=0;i<n;i++){
		sit=stamp.begin();
		for(;sit!=stamp.end();sit++){
			if(sit->first==ans[ans.size()-1]){
				ans.push_back(sit->second);
				stamp.erase(sit);
				break;
			}
			else if(sit->second==ans[ans.size()-1]){
				ans.push_back(sit->first);
				stamp.erase(sit);
				break;
			}
		}
		cout<<ans[i]<<" ";
	}cout<<ans[n]<<endl;

	return 0;
}*/


#include<iostream>
#include<set>
#include<vector>
using namespace std;

int main(){
	set<pair<int,int> > stamp;
	set<int> mark;
	set<int>::iterator it;
	int n,a,b;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		stamp.insert(make_pair(a,b));
		it=mark.find(a);
		if(it==mark.end())mark.insert(a);
		else	mark.erase(it);
	}
	vector<int> ans;
	ans.push_back(*mark.begin());
	set<pair<int,int> >::iterator sit;
	for(int i=0;i<n;i++){
		sit=stamp.begin();
		for(;sit!=stamp.end();sit++){
			if(sit->first==ans[ans.size()-1]){
				ans.push_back(sit->second);
				stamp.erase(sit);
				break;
			}
			else if(sit->second==ans[ans.size()-1]){
				ans.push_back(sit->first);
				stamp.erase(sit);
				break;
			}
		}
		cout<<ans[i]<<" ";
	}cout<<ans[n]<<endl;

	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

struct edge
{
    int u,v;
}e[110000];

int a[220000],b[110000][2],c[110000];
int low_bound(int a[],int t,int num)
{
    int l=0,r=num-1,mid;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(a[mid]==t)
            return mid;
        else if(a[mid]>t)
            r=mid-1;
        else l=mid+1;
    }
}
int main()
{
    int n,i,j,k,num;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            c[i]=0;
            scanf("%d%d",&e[i].u,&e[i].v);
            a[2*i]=e[i].u,a[2*i+1]=e[i].v;
        }
        sort(a,a+2*n);
        num=unique(a,a+2*n)-a;
        for(i=0;i<n;i++)
        {
            j=low_bound(a,e[i].u,num);
            k=low_bound(a,e[i].v,num);
            b[j][c[j]++]=k;
            b[k][c[k]++]=j;
        }
        for(i=0;i<num;i++)
            if(c[i]==1)
                break;
        printf("%d",a[i]);
        j=b[i][0],k=i;
        while(1)
        {
            printf(" %d",a[j]);
            if(c[j]==1)
                break;

            if(b[j][0]!=i)
            {
                k=j;
                j=b[j][0];
            }
            else
            {
                k=j;
                j=b[j][1];
            }
        }
        printf("\n");
    }
    return 0;
}


#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

map<int,vector<int> >e;
int main()
{
    int n,u,v,i,start;
    while(scanf("%d",&n)!=EOF)
    {
        e.clear();
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&u,&v);
            e[u].push_back(v);
            e[v].push_back(u);
        }
        start=-1;
        map<int,vector<int> >::iterator i;
        for(i=e.begin();i!=e.end();i++)
            if(i->second.size()==1)
            {
                start=i->first;
                break;
            }
        printf("%d",start);
        int pre=start;
        start=e[start][0];
        while(1)
        {
            printf(" %d",start);
            if(e[start].size()==1)
                break;

            if(e[start][0]==pre)
            {
                pre=start;
                start=e[start][1];
            }
            else
            {
                pre=start;
                start=e[start][0];
            }
        }
        printf("\n");
    }
    return 0;
}


#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

map<int,vector<int> >e;
int main()
{
    int n,u,v,i,start;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&u,&v);
            e[u].push_back(v);
            e[v].push_back(u);
        }
        start=-1;
        i=map<int,vector<int> >::iterator;
        for(i=e.begin();i!=e.end();i++)
            if(i->second.size()==1)
            {
                start=i->first;
                break;
            }
        printf("%d",start);
        int pre=start;
        start=e[start][0];
        while(1)
        {
            printf(" %d",start);
            if(e[start].size()==1)
                break;

            if(e[start][0]==pre)
            {
                pre=start;
                start=e[start][1];
            }
            else
            {
                pre=start;
                start=e[start][0];
            }
        }
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <map>

using namespace std;

struct node
{
	int x,y;
};
int n;
int next1[100010],next2[100010];
node no[100010];
int res[100010];
		map<int,int> ma;
		map<int,int>::iterator itor;
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int a,b;
		int i,j;
		int num=-1;
		memset(next1,-1,sizeof(next1));
		memset(next2,-1,sizeof(next2));
		ma.clear();
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			no[i].x=a;no[i].y=b;
			itor=ma.find(a);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(a,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[tnum]=i;
			}
			itor=ma.find(b);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(b,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[tnum]=i;
			}
		}
		int resnum=0;
		int nowynum;
		int nownum,nextnum;
		for(i=0;i<n;i++)
		{
			itor=ma.find(no[i].x);
			int tnum=itor->second;
		if(next1[tnum]==-1||next2[tnum]==-1)
		{
			itor=ma.find(no[i].y);
			tnum=itor->second;
			nowynum=tnum;
			nownum=i;
			res[resnum++]=no[i].x;
			res[resnum++]=no[i].y;
			break;
		}
			itor=ma.find(no[i].y);
			tnum=itor->second;
		if(next1[tnum]==-1||next2[tnum]==-1)
		{
			itor=ma.find(no[i].x);
			tnum=itor->second;
			nowynum=tnum;
			nownum=i;
			res[resnum++]=no[i].y;
			res[resnum++]=no[i].x;
			break;
		}
		}
		while(resnum<=n)
		{
			if(next1[nowynum]!=nownum)
			{
				nextnum=next1[nowynum];
			}
			else
			{
				nextnum=next2[nowynum];
			}
				nownum=nextnum;
				itor=ma.find(no[nextnum].x);
				if(nowynum!=itor->second)
				{
					res[resnum++]=no[nextnum].x;
					nowynum=itor->second;
				}
				else
				{
					res[resnum++]=no[nextnum].y;
					itor=ma.find(no[nextnum].y);
					nowynum=itor->second;
				}
		}
			for(i=0;i<resnum;i++)
				printf("%d ",res[i]);
			printf("\n");
	}
	return 0;
}


#include <iostream>
#include <map>

using namespace std;

struct node
{
	int x,y;
};
int n;
int next1[100001],next2[100001];
node no[100001];
int res[100001];
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int a,b;
		int i,j;
		int num=-1;
		memset(next1,-1,sizeof(next1));
		memset(next2,-1,sizeof(next2));
		map<int,int> ma;
		map<int,int>::iterator itor;
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			no[i].x=a;no[i].y=b;
			itor=ma.find(a);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(a,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[tnum]=i;
			}
			itor=ma.find(b);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(b,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[num]=i;
			}
		}
		int resnum=0;
		int nowynum;
		int nownum=0,nextnum;
		if(next1[0]!=-1&&next2[0]!=-1)
		{
			nowynum=0;
			res[resnum++]=no[0].y;
			res[resnum++]=no[0].x;
		}
		else
		{
			nowynum=1;
			res[resnum++]=no[0].x;
			res[resnum++]=no[0].y;
		}
		while(resnum<=n)
		{
			if(next1[nowynum]!=nownum)
			{
				nextnum=next1[nowynum];
			}
			else
			{
				nextnum=next2[nowynum];
			}
				nownum=nextnum;
				itor=ma.find(no[nextnum].x);
				if(nowynum!=itor->second)
				{
					res[resnum++]=no[nextnum].x;
					nowynum=itor->second;
				}
				else
				{
					res[resnum++]=no[nextnum].y;
					itor=ma.find(no[nextnum].y);
					nowynum=itor->second;
				}
		}
			for(i=0;i<resnum;i++)
				printf("%d ",res[i]);
			printf("\n");
	}
	return 0;
}


#include <iostream>
#include <map>

using namespace std;

struct node
{
	int x,y;
};
int n;
int next1[100010],next2[100010];
node no[100010];
int res[100010];
		map<int,int> ma;
		map<int,int>::iterator itor;
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int a,b;
		int i,j;
		int num=-1;
		memset(next1,-1,sizeof(next1));
		memset(next2,-1,sizeof(next2));
		ma.clear();
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			no[i].x=a;no[i].y=b;
			itor=ma.find(a);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(a,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[tnum]=i;
			}
			itor=ma.find(b);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(b,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[num]=i;
			}
		}
		int resnum=0;
		int nowynum;
		int nownum=0,nextnum;
		if(next1[0]!=-1&&next2[0]!=-1)
		{
			nowynum=0;
			res[resnum++]=no[0].y;
			res[resnum++]=no[0].x;
		}
		else
		{
			nowynum=1;
			res[resnum++]=no[0].x;
			res[resnum++]=no[0].y;
		}
		while(resnum<=n)
		{
			if(next1[nowynum]!=nownum)
			{
				nextnum=next1[nowynum];
			}
			else
			{
				nextnum=next2[nowynum];
			}
				nownum=nextnum;
				itor=ma.find(no[nextnum].x);
				if(nowynum!=itor->second)
				{
					res[resnum++]=no[nextnum].x;
					nowynum=itor->second;
				}
				else
				{
					res[resnum++]=no[nextnum].y;
					itor=ma.find(no[nextnum].y);
					nowynum=itor->second;
				}
		}
			for(i=0;i<resnum;i++)
				printf("%d ",res[i]);
			printf("\n");
	}
	return 0;
}


#include <iostream>
#include <map>

using namespace std;

struct node
{
	int x,y;
};
int n;
int next1[100010],next2[100010];
node no[100010];
int res[100010];
		map<int,int> ma;
		map<int,int>::iterator itor;
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int a,b;
		int i,j;
		int num=-1;
		memset(next1,-1,sizeof(next1));
		memset(next2,-1,sizeof(next2));
		ma.clear();
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			no[i].x=a;no[i].y=b;
			itor=ma.find(a);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(a,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[tnum]=i;
			}
			itor=ma.find(b);
			if(itor==ma.end())
			{
				num++;
				ma.insert(pair<int,int>(b,num));
				next1[num]=i;
			}
			else
			{
				int tnum=itor->second;
				next2[tnum]=i;
			}
		}
		int resnum=0;
		int nowynum;
		int nownum=0,nextnum;
		if(next1[0]!=-1&&next2[0]!=-1)
		{
			nowynum=0;
			res[resnum++]=no[0].y;
			res[resnum++]=no[0].x;
		}
		else
		{
			nowynum=1;
			res[resnum++]=no[0].x;
			res[resnum++]=no[0].y;
		}
		while(resnum<=n)
		{
			if(next1[nowynum]!=nownum)
			{
				nextnum=next1[nowynum];
			}
			else
			{
				nextnum=next2[nowynum];
			}
				nownum=nextnum;
				itor=ma.find(no[nextnum].x);
				if(nowynum!=itor->second)
				{
					res[resnum++]=no[nextnum].x;
					nowynum=itor->second;
				}
				else
				{
					res[resnum++]=no[nextnum].y;
					itor=ma.find(no[nextnum].y);
					nowynum=itor->second;
				}
		}
			for(i=0;i<resnum;i++)
				printf("%d ",res[i]);
			printf("\n");
	}
	return 0;
}


#include<iostream>
#include<map>
#include<vector>
#define mapit map<int,vector<int>>::iterator
using namespace std;
map<int,vector<int>> mails;bool visited[100001];
void dfs(int n)
{
    if(visited[n]) return;visited[n]=true;
    cout<<n<<" ";
    for(int j=0;j<mails[n].size();j++)
            dfs(mails[n][j]);
}
void main()
{
    int n,a,b,ver;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        mails[a].push_back(b);
        mails[b].push_back(a);
    }
    for(mapit i=mails.begin();i!=mails.end();i++)
        if(i->second.size()==1){ dfs(i->first);break;}
    dfs(ver);
}


#include<iostream>
#include<map>
#include<vector>
#define mapit map<int,vector<int>>::iterator
using namespace std;
map<int,vector<int>> mails;
map<int,bool> visited;
void dfs(int n)
{
    if(visited[n]||mails[n].empty()) return;visited[n]=true;
    cout<<n<<" ";
    for(int j=0;j<mails[n].size();j++)
            dfs(mails[n][j]);
}
void main()
{
    int n,a,b,ver;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        mails[a].push_back(b);
        mails[b].push_back(a);
    }
    for(mapit i=mails.begin();i!=mails.end();i++)
        if(i->second.size()==1){ dfs(i->first);break;}
    dfs(ver);
}


#include<iostream>
using namespace std;
#include<utility>
#include<map>
#include<vector>
map<int,vector<int>> mails;
map<int,bool> visited;
void dfs(int n)
{
    if(visited[n]) return;
    visited[n]=true;
    cout<<n<<" ";
    for(int j=0;j<mails[n].size();j++)
            dfs(mails[n][j]);
}
void main()
{
    int n,a,b,ver;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        mails[a].push_back(b);
        mails[b].push_back(a);
       if(mails[a].size()==1)ver=a;
       else if(mails[b].size()==1) ver=b;
    }
    dfs(ver);
}


#include<iostream>
#include<map>
#include<vector>
#define mapit map<int,vector<int>>::iterator
using namespace std;
map<int,vector<int>> mails;
map<int,bool> visited;
void dfs(int n)
{
    if(visited[n]) return;visited[n]=true;
    cout<<n<<" ";
    for(int j=0;j<mails[n].size();j++)
            dfs(mails[n][j]);
}
void main()
{
    int n,a,b,ver;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        mails[a].push_back(b);
        mails[b].push_back(a);
    }
    for(mapit i=mails.begin();i!=mails.end();i++)
        if(i->second.size()==1){ dfs(i->first);break;}
    dfs(ver);
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define forr(i,a,b) for(int i = (a); i <= (b); ++i)

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a, b;
    map<int, vector<int> > adj;
    map<int, vector<int> >::iterator it;
    rep(i,n)
    {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int city = -1;
    for(it = adj.begin(); it != adj.end(); ++it)
        if (it->second.size() == 1)
        {
            city = it->first;
            break;
        }

    cout << city;
    int prevCity = city;
    for (city = adj[city][0]; adj[city].size() == 2;)
    {
        cout << " " << city;

        int nextCity = adj[city][0] ^ prevCity ^ adj[city][1];
        prevCity = city;
        city = nextCity;
    }
    cout << " " << city << endl;

    return 0;
}


#pragma warning( disable : 4996)
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#ifndef ONLINE_JUDGE
typedef vector<int> vc;
typedef vector<vc> vvc;
#else
typedef vector<char> vc;
typedef vector<char> vvc;
#endif

typedef list<int> li;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML(const bool v)
{
    if (v)
        return;
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

void TL(const bool v)
{
    if (v)
        return;
    int *ass;
        ass = new int[250];
    for (;;)
    {
        for (int i = 0; i < 250; i++)
            ass[i] = rand();
    }
}

void PE(const bool v)
{
    if (v)
        return;
    puts("ass 1 2 3 4 5 6 fuck");
    exit(0);
}

map<int, pii> w;

void add_edge(const int f, const int t, const bool v = true)
{
    if (w.find(f) == w.end())
        w[f] = mp(t, -1);
    else
        w[f].second = t;
    if (v)
        add_edge(t, f, false);
}

void LoAd()
{
    int n;
    cin >> n;
    for (int f, t, i = 0; i < n; i++)
    {
        scanf("%d%d", &f, &t);
        add_edge(f, t);
    }
}

void dfs(const int v, const int p)
{
    printf("%d ", v);
    pii nxt = w[v];
    if (nxt.first != p && nxt.first != -1)
        dfs(nxt.first, v);
    if (nxt.second != p && nxt.second != -1)
        dfs(nxt.second, v);
}

void SoLvE()
{
    for (auto it = w.begin(); it != w.end(); it++)
    {
        if (it->second.second == -1)
        {
            dfs(it->first, -1);
            return;
        }
    }
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

struct dotinfo
{
    int x;
    int y;
};

bool dotslt(dotinfo a,dotinfo b)
{
    if(a.x<=b.x)
    {
        if(a.x==b.x)
        {
            if(a.y<b.y)
                return 1;
            else
                return 0;
        }
        else
            return 1;
    }
    else
        return 0;
}

dotinfo dot[200002];
int chk[200002],cnt;
int re[100003];

int main()
{
    int i,j;
    int n,st,ed,mid,yet,pl;

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&dot[i].x);
        chk[cnt++]=dot[i].x;
        scanf("%d",&dot[i].y);
        chk[cnt++]=dot[i].y;
        dot[n+i].x=dot[i].y;
        dot[n+i].y=dot[i].x;
    }
    if(n==1)
    {
        printf("%d %d\n",dot[0].x,dot[0].y);
        return 0;
    }
    sort(&chk[0],&chk[cnt]);
    for(i=0;i<cnt-1;i+=2)
    {
        if(chk[i]!=chk[i+1])
        {
            pl=chk[i];
            break;
        }
    }

    sort(&dot[0],&dot[n*2],dotslt);

    for(i=0;i<n*2;i++)
    {
        if(dot[i].x==pl)
        {
            yet=dot[i].x;
            pl=dot[i].y;
            break;
        }
    }

    re[0]=yet;
    re[1]=pl;
    cnt=2;
    while(1)
    {
        st=0;
        ed=n*2;

        while(1)
        {
            if(st>ed)
                break;
            mid=(st+ed)/2;
            if(dot[mid].x==pl)
            {
                if(mid>0 && dot[mid-1].x==dot[mid].x)
                    mid--;
                break;
            }
            else if(dot[mid].x<pl)
                st=mid+1;
            else
                ed=mid-1;
        }

        if(dot[mid].y==yet)
            mid++;
        yet=pl;
        pl=dot[mid].y;
        re[cnt++]=pl;
        if(cnt==n+1)
            break;
    }
    for(i=0;i<cnt;i++)
        printf("%d ",re[i]);
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

struct dotinfo
{
    int x;
    int y;
};

bool dotslt(dotinfo a,dotinfo b)
{
    if(a.x<=b.x)
    {
        if(a.x==b.x)
        {
            if(a.y<b.y)
                return 1;
            else
                return 0;
        }
        else
            return 1;
    }
    else
        return 0;
}

dotinfo dot[200002];
int chk[200002],cnt;
int re[100003];

int main()
{
    int i,j;
    int n,st,ed,mid,yet,pl;

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&dot[i].x);
        chk[cnt++]=dot[i].x;
        scanf("%d",&dot[i].y);
        chk[cnt++]=dot[i].y;
        dot[n+i].x=dot[i].y;
        dot[n+i].y=dot[i].x;
    }
    sort(&chk[0],&chk[cnt]);
    for(i=0;i<cnt-1;i+=2)
    {
        if(chk[i]!=chk[i+1])
        {
            pl=chk[i];
            break;
        }
    }

    sort(&dot[0],&dot[n*2],dotslt);

    for(i=0;i<n*2;i++)
    {
        if(dot[i].x==pl)
        {
            yet=dot[i].x;
            pl=dot[i].y;
            break;
        }
    }

    re[0]=yet;
    re[1]=pl;
    cnt=2;
    while(1)
    {
        st=0;
        ed=n*2;

        while(1)
        {
            if(st>ed)
                break;
            mid=(st+ed)/2;
            if(dot[mid].x==pl)
            {
                if(mid>0 && dot[mid-1].x==dot[mid].x)
                    mid--;
                break;
            }
            else if(dot[mid].x<pl)
                st=mid+1;
            else
                ed=mid-1;
        }

        if(dot[mid].y==yet)
            mid++;
        yet=pl;
        pl=dot[mid].y;
        re[cnt++]=pl;
        if(cnt==n+1)
            break;
    }
    for(i=0;i<cnt;i++)
        printf("%d ",re[i]);
    printf("\n");
    return 0;
}


#include <iostream>
#include <map>
#include <cstdio>
using namespace std;

struct a{
    int to[2];
};

map<int,int> cnt;
map<int, a > ed;

int main(){
    int n;
    cin>>n;
    int v,u;
    for( int i = 0; i < n; i++ ){
        cin>>v>>u;
        ed[v].to[ cnt[v] ] = u;
        ed[u].to[ cnt[u] ] = v;
        cnt[u]++;
        cnt[v]++;
    }

    int cur;
    for( map<int,int>::iterator it = cnt.begin(); it!=cnt.end(); it++ ){
        if( it->second==1 ){
            cur = it->first;
            break;
        }
    }
    cout<<cur;
    int z = 0;
    int prev;
    for( int i = 0; i < n; i++ ){
        prev = cur;
        cur = ed[cur].to[z];
        cout<<" "<<cur;
        if( i==n-1 ) break;
        if( ed[cur].to[0] !=prev )
            z = 0;
        else z=1;
    }

}
/*
6
1 2
3 1
4 3
2 5
5 6
7 4
1 2 5 6 0 0 0
*/


#include <iostream>
#include <map>
#include <cstdio>
using namespace std;

struct a{
    int to[2];
};

map<int,int> cnt;
map<int, a > ed;

int main(){
    int n;
    cin>>n;
    int v,u;
    for( int i = 0; i < n; i++ ){
        cin>>v>>u;
        ed[v].to[ cnt[v] ] = u;
        ed[u].to[ cnt[u] ] = v;
        cnt[u]++;
        cnt[v]++;
    }
    int cur = cnt.begin()->first;
    cout<<cur;
    int z = 0;
    int prev;
    for( int i = 0; i < n; i++ ){
        prev = cur;
        cur = ed[cur].to[z];
        cout<<" "<<cur;
        if( i==n-1 ) break;
        if( ed[cur].to[0] !=prev )
            z = 0;
        else z=1;
    }

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <set>
#include <map>

using namespace std;
#define forn(i,n) for(int i = 0; i < (n); ++i)
#define forn1(i,n) for(int i = 1; i <= (n); ++i)
#define forr(i,n) (int i = (n)-1; i >= 0; i--)
#define forr1(i,n) (int i = (n); i >= 1; i--)
//#define forit(it,x) (it = x.begin(); it != x.end(); ++it)

#define sz size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()

typedef long long int64;
typedef vector < int64 > vi64;
typedef vector <int> vi;
typedef vector <string> vs;
typedef pair<int,int> pii;
typedef vector < pii > vpii;
typedef vector < vi > vvi;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("ReadMe.txt","r",stdin);
#endif
	int n;cin >> n;
	map< int, vi > m;

	forn(i,n)
	{
		int a,b;
		cin >> a >> b;
		m[a].pb(b);
		m[b].pb(a);
	}

	vi st;
	for(map< int, vi >::iterator it = m.begin(); it != m.end(); it++)
	{
		if(it->second.sz == 1)
		{
			st.push_back(it->first);
		}
	}

	for(int v = st.front(),pred = st.front(); v != st.back();)
	{
		int to;
		if(pred == v)
		{
			to = m[v][0];
			cout << v << ' ' << to << ' ';
		}
		else
		{
			to = (m[v][0] == pred? m[v][1] : m[v][0]) ;
			cout << to << ' ';
		}

		pred = v;
		v = to;
	}

	cout << endl;

	return 0;
}


#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <limits>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;

const double eps = 1e-8;

int main()
{
    int n, t, u, v;
    map<int, vector<int> > mp;
    map<int, bool> used;
    map<int, vector<int> >::iterator p;

    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d %d", &u, &v);
        used.insert(make_pair(u, 0));
        used.insert(make_pair(v, 0));
        p = mp.find(u);
        if( p == mp.end() )
        {
            vector<int> vt;
            vt.push_back(v);
            mp.insert(make_pair(u, vt));
        }
        else
            p->second.push_back(v);
        p = mp.find(v);
        if( p == mp.end() )
        {
            vector<int> vt;
            vt.push_back(u);
            mp.insert(make_pair(v, vt));
        }
        else
            p->second.push_back(u);
    }

    for(p=mp.begin(); p!=mp.end(); p++)
        if( p->second.size() == 1 )
        {
            t = p->first;
            printf("%d", t);
            break;
        }
    while( 1 )
    {
        bool flags = false;
        used.find(t)->second = true;
        p = mp.find(t);
        for(int i=0; i<(int)p->second.size(); i++)
            if( !used.find(p->second[i])->second )
            {
                flags = true;
                t = p->second[i];
                printf(" %d", t);
            }
        if( flags == false )
            break;
    }
    printf("\n");

    return 0;
}


#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <limits>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;

const double eps = 1e-8;

bool used[1000000010];

int main()
{
    int n, t, u, v;
    map<int, vector<int> > mp;
    map<int, vector<int> >::iterator p;

    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d %d", &u, &v);
        p = mp.find(u);
        if( p == mp.end() )
        {
            vector<int> vt;
            vt.push_back(v);
            mp.insert(make_pair(u, vt));
        }
        else
            p->second.push_back(v);
        p = mp.find(v);
        if( p == mp.end() )
        {
            vector<int> vt;
            vt.push_back(u);
            mp.insert(make_pair(v, vt));
        }
        else
            p->second.push_back(u);
    }

    for(p=mp.begin(); p!=mp.end(); p++)
        if( p->second.size() == 1 )
        {
            t = p->first;
            printf("%d", t);
            break;
        }
    while( 1 )
    {
        bool flags = false;
        used[t] = true;
        p = mp.find(t);
        for(int i=0; i<(int)p->second.size(); i++)
            if( !used[p->second[i]] )
            {
                flags = true;
                t = p->second[i];
                printf(" %d", t);
            }
        if( flags == false )
            break;
    }
    printf("\n");

    return 0;
}


#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <limits>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;

const double eps = 1e-8;

bool used[100010];

int main()
{
    int n, t, u, v;
    map<int, vector<int> > mp;
    map<int, vector<int> >::iterator p;

    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d %d", &u, &v);
        p = mp.find(u);
        if( p == mp.end() )
        {
            vector<int> vt;
            vt.push_back(v);
            mp.insert(make_pair(u, vt));
        }
        else
            p->second.push_back(v);
        p = mp.find(v);
        if( p == mp.end() )
        {
            vector<int> vt;
            vt.push_back(u);
            mp.insert(make_pair(v, vt));
        }
        else
            p->second.push_back(u);
    }

    for(p=mp.begin(); p!=mp.end(); p++)
        if( p->second.size() == 1 )
        {
            t = p->first;
            printf("%d", t);
            break;
        }
    while( 1 )
    {
        bool flags = false;
        used[t] = true;
        p = mp.find(t);
        for(int i=0; i<(int)p->second.size(); i++)
            if( !used[p->second[i]] )
            {
                flags = true;
                t = p->second[i];
                printf(" %d", t);
            }
        if( flags == false )
            break;
    }
    printf("\n");

    return 0;
}


#include <iostream>
#include <map>
using namespace std;

int n;
map<int, bool> used;
map<int, pair<int, int>> adj;
int st = -1, fin = -1;

int main()
{
    cin >> n;
    for (int i = 0, a, b; i < n; ++i)
    {
        cin >> a >> b;
        if (adj[a].first)
            adj[a].second = b;
        else adj[a].first = b;
        if (adj[b].first)
            adj[b].second = a;
        else adj[b].first = a;
    }
    for (map<int, pair<int, int>>::iterator it = adj.begin(); it != adj.end(); ++it)
    {
        if (!it->second.second)
            if (st < 0)
                st = it->first;
            else fin = it->first;
    }
    int x = st;
    used[x] = true;
    while (x)
    {
        printf("%d ", x);
        pair<int, int> to = adj[x];
        if (!used[to.first])
        {
            used[to.first] = true;
            x = to.first;
        }
        else
        {
            used[to.second] = true;
            x = to.second;
        }
    }
    puts("");
    return 0;
}