#include <iostream>
#include <cstring>
using namespace std;
 
const int MAX_SIZE = 20;
 
void sortWords(char words[][MAX_SIZE + 1], int lastWord) {
    for (int i = 0; i < lastWord; ++i) {
        for (int j = i + 1; j < lastWord; ++j) {
            if (strcmp(words[i] , words[j]) > 0) {
                char aux[MAX_SIZE + 1];
                strcpy(aux, words[j]);
                strcpy(words[j], words[i]);
    	        strcpy(words[i], aux);
            }
        }
    }
}
 
void convertLineToWords(char words[][MAX_SIZE + 1], char line[], int &lastWord) {
    for (int i = 0, j = 0; line[i]; ++i) {
        if (line[i] == ' ') {
            ++lastWord;
            j = i + 1;
            continue;
        }
        words[lastWord][i - j] = line[i];
    }
    if (words[lastWord][0]) {
    	++lastWord;
    }
}
 
int main() {
    char firstLine[MAX_SIZE + 1];
    cin.getline(firstLine, MAX_SIZE + 1);
    char firstWords[MAX_SIZE / 2][MAX_SIZE + 1] = {0}, secondWords[MAX_SIZE / 2][MAX_SIZE + 1];
    int firstLastWord = 0, secondLastWord = 0;
    convertLineToWords(firstWords, firstLine, firstLastWord);
    while (cin >> secondWords[secondLastWord]) {
        ++secondLastWord;
    }
    sortWords(firstWords, firstLastWord);
    sortWords(secondWords, secondLastWord);
    for (int i = 0; firstWords[0][0] && i < firstLastWord; ++i) {
        for (int j = 0; secondWords[0][0] && j < secondLastWord; ++j) {
            cout << firstWords[i] << ' ' << secondWords[j] << '\n';
        }
    }
    return 0;
}