#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 1000000000;
int n, match[N], taken[N];
string s;
struct node {
  int f[2];
  vector<int> v[2];
  node *nxt[26];
  node() {
    f[0] = f[1] = 0;
    for (int i = 0; i < 26; ++i) nxt[i] = NULL;
  }
} * root;
void add(bool d, int idx) {
  node *cur = root;
  cur->v[d].push_back(idx);
  for (int i = 0; i < s.size(); ++i) {
    int c = s[i] - 'a';
    if (!cur->nxt[c]) cur->nxt[c] = new node();
    cur = cur->nxt[c];
    ++cur->f[d];
    cur->v[d].push_back(idx);
  }
}
int get(node *cur) {
  if (!cur) return 0;
  int ans = min(cur->f[0], cur->f[1]);
  for (int i = 0; i < 26; ++i) ans += get(cur->nxt[i]);
  int j = 0;
  while (j < cur->v[1].size() && taken[cur->v[1][j]]) ++j;
  for (int i = 0; i < cur->v[0].size() && j < cur->v[1].size(); ++i) {
    int d = cur->v[0][i];
    if (match[d]) continue;
    match[d] = cur->v[1][j];
    taken[cur->v[1][j]] = 1;
    while (j < cur->v[1].size() && taken[cur->v[1][j]]) ++j;
  }
  return ans;
}
int main() {
  cin >> n;
  root = new node();
  for (int i = 0; i < 2 * n; ++i) {
    cin >> s;
    add(i >= n, i % n + 1);
  }
  cout << get(root) << endl;
  for (int i = 1; i < n + 1; ++i) printf("%d %d\n", i, match[i]);
}
