#include <bits/stdc++.h>
using namespace std;
int n;
int redundant[30], unmatched[30];
vector<string> names[30], surnames[30];
string answer;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    s += " ";
    names[s[0] - 'A'].push_back(s);
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    s += ", ";
    surnames[s[0] - 'A'].push_back(s);
  }
  for (char c = 'A'; c <= 'Z'; c++) {
    sort(names[c - 'A'].begin(), names[c - 'A'].end());
    sort(surnames[c - 'A'].begin(), surnames[c - 'A'].end());
    unmatched[c - 'A'] =
        max(0, int(names[c - 'A'].size() - surnames[c - 'A'].size()));
    redundant[c - 'A'] =
        max(0, int(surnames[c - 'A'].size() - names[c - 'A'].size()));
  }
  for (int c1 = 'A'; c1 <= 'Z'; c1++) {
    for (int i = 0; i < names[c1 - 'A'].size(); i++) {
      answer += names[c1 - 'A'][i];
      if (surnames[c1 - 'A'].size() > 0 && unmatched[c1 - 'A'] <= 0) {
        answer += surnames[c1 - 'A'][0];
        surnames[c1 - 'A'].erase(surnames[c1 - 'A'].begin());
      } else {
        unmatched[c1 - 'A']--;
        for (char c2 = 'A'; c2 <= 'Z'; c2++) {
          if (redundant[c2 - 'A'] > 0 ||
              (c2 == c1 && surnames[c1 - 'A'].size() > 0)) {
            answer += surnames[c2 - 'A'][0];
            redundant[c2 - 'A']--;
            surnames[c2 - 'A'].erase(surnames[c2 - 'A'].begin());
            break;
          }
        }
      }
    }
  }
  answer.erase(answer.size() - 2, 2);
  cout << answer << '\n';
}
