#include <bits/stdc++.h>
using namespace std;
const int maxn = 800005;
vector<int> a[2][maxn];
int g[maxn * 2][26], cou;
void add(int type, int num, char* ch) {
  int i = 0, now = 0, va;
  while (ch[i]) {
    va = ch[i] - 'a';
    if (g[now][va] == 0) {
      g[now][va] = cou++;
    }
    a[type][g[now][va]].push_back(num);
    now = g[now][va];
    i++;
  }
}
int match[100005], matched[100005], n;
long long ans;
void find_match() {
  int i, x, y;
  i = cou - 1;
  while (i) {
    ans += min(a[0][i].size(), a[1][i].size());
    x = y = 0;
    while (x < a[0][i].size() && y < a[1][i].size()) {
      if (match[a[0][i][x]] != 0) {
        x++;
        continue;
      }
      if (matched[a[1][i][y]] != 0) {
        y++;
        continue;
      }
      match[a[0][i][x]] = a[1][i][y];
      matched[a[1][i][y]] = a[0][i][x];
      x++;
      y++;
    }
    i--;
  }
  x = 1;
  y = 1;
  while (x <= n) {
    if (match[x] == 0) {
      while (matched[y] != 0) y++;
      match[x] = y;
      y++;
    }
    x++;
  }
}
void init() {
  cou = 1;
  ans = 0;
}
char in[maxn];
int main() {
  int i, j;
  cin >> n;
  init();
  for (i = 0; i <= 1; i++)
    for (j = 1; j <= n; j++) {
      scanf("%s", in);
      add(i, j, in);
    }
  find_match();
  cout << ans << endl;
  for (i = 1; i <= n; i++) printf("%d %d\n", i, match[i]);
  return 0;
}
