#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e5) + 5;
int match[maxn];
string A[maxn][2];
struct ppnode {
  int sig[2] = {0}, val[2] = {0};
  vector<int> undone[2];
  ppnode* child[27] = {NULL};
};
typedef ppnode* pnode;
void insert(pnode& root, int sidx, int idx, int type) {
  root->sig[type]++;
  if (sidx == int(A[idx][type].size())) {
    root->val[type]++;
    root->undone[type].push_back(idx);
    return;
  }
  int ch = int(A[idx][type][sidx] - 'a');
  if (!root->child[ch]) root->child[ch] = new ppnode();
  insert(root->child[ch], sidx + 1, idx, type);
}
int solve(pnode& root) {
  int res = 0;
  for (int i = 0; i < 26; i++) {
    if (!root->child[i]) continue;
    res += solve(root->child[i]);
    for (auto it : (root->child[i])->undone[0]) root->undone[0].push_back(it);
    for (auto it : (root->child[i])->undone[1]) root->undone[1].push_back(it);
  }
  int sz = min(root->sig[0], root->sig[1]);
  if (sz && !root->undone[0].empty() && !root->undone[1].empty()) {
    int tmp = 0;
    for (auto it = root->undone[0].rbegin(), gt = root->undone[1].rbegin();
         it != root->undone[0].rend() && gt != root->undone[1].rend();
         it++, gt++) {
      match[*it] = *gt;
      sz--, tmp++;
      if (!sz) break;
    }
    root->undone[0].resize(int(root->undone[0].size()) - tmp);
    root->undone[1].resize(int(root->undone[1].size()) - tmp);
  }
  return res + min(root->sig[0], root->sig[1]);
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> A[i][0];
  for (int i = 0; i < n; i++) cin >> A[i][1];
  pnode root = new ppnode();
  for (int i = 0; i < n; i++) {
    insert(root, 0, i, 0);
    insert(root, 0, i, 1);
  }
  int res = solve(root);
  printf("%d\n", res - n);
  for (int i = 0; i < n; i++) printf("%d %d\n", i + 1, match[i] + 1);
}
