#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApjb25zdCBpbnQgTUFYX1NJWkUgPSAyMDsKIAp2b2lkIHNvcnRXb3JkcyhjaGFyIHdvcmRzW11bTUFYX1NJWkUgKyAxXSwgaW50IGxhc3RXb3JkKSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxhc3RXb3JkOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0gaSArIDE7IGogPCBsYXN0V29yZDsgKytqKSB7CiAgICAgICAgICAgIGlmIChzdHJjbXAod29yZHNbaV0gLCB3b3Jkc1t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