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

using namespace std;

#ifndef IOSTACKFUNCTIONS
#define IOSTACKFUNCTIONS

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

// Addapt the header of the function to your case
queue<int> maximumQueue(queue<int> q1,queue<int> q2);

queue<int> readQueue(string s)
{
    istringstream mycin(s);
    queue<int> q;
    int x;
    while (mycin >> x)
        q.push(x);
    return q;
}

void writeQueue(queue<int> q)
{
    bool writespace = false;
    while (not q.empty()) {
        if (writespace) cout << " ";
        cout << q.front();
        q.pop();
        writespace = true;
    }
    cout << endl;
}
#endif

int main()  {
	vector<Test> v;
    string s;
    while (getline(cin, s)) {
        Test t;
        t.q1=readQueue(s);
        getline(cin, s);
        t.q2=readQueue(s);
        v.push_back(t);
    }
    for (int i = 0; i < int(v.size()); ++i) {
        writeQueue(maximumQueue(v[i].q1,v[i].q2));
    }
}
