// Add or remove includes
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <sstream>

using namespace std;

#ifndef IOSTACKFUNCTIONS
#define IOSTACKFUNCTIONS

struct Test {
    stack<int> q1,q2;
};

// Addapt the header of the function to your case
stack<int> maximumStack(stack<int> s1,stack<int> s2);

stack<int> readStack(string line)
{
    istringstream mycin(line);
    stack<int> s;
    int x;
    while (mycin >> x)
        s.push(x);
    return s;
}


void writeStackRec(stack<int> &s)
{
    if (s.empty()) return;
    int x = s.top();
    s.pop();
    bool writespace = not s.empty();
    writeStackRec(s);
    if (writespace) cout << " ";
    cout << x;
}

void writeStack(stack<int> s)
{
    writeStackRec(s);
    cout << endl;
}

#endif


int main()  {
    vector<Test> v;
    string s;
    while (getline(cin, s)) {
        Test t;
        t.q1=readStack(s);
        getline(cin, s);
        t.q2=readStack(s);
        v.push_back(t);
    }
    for (int i=0;i<int(v.size());i++) {
        stack<int> s;
        for (int j = 0; j < 50; ++j)
        	s = maximumStack(v[i].q1,v[i].q2);
        writeStack(s);
    }
}
