#include <bits/stdc++.h>
using namespace std;
string s;
int len, cur;
set<int> used1, used2;
vector<pair<int, int> > v;
struct trie {
  int num1, num2, intree1, intree2;
  vector<int> ind1;
  vector<int> ind2;
  trie* child[26];
  trie() {
    num1 = 0;
    intree1 = 0;
    num2 = 0;
    intree2 = 0;
    for (int i = 0; i < 26; i++) child[i] = NULL;
  }
  void rec1(int pos) {
    intree1++;
    ind1.push_back(cur);
    if (pos == len) {
      num1++;
      return;
    }
    int c = s[pos] - 'a';
    if (child[c] == NULL) child[c] = new trie();
    child[c]->rec1(pos + 1);
  }
  void rec2(int pos) {
    intree2++;
    ind2.push_back(cur);
    if (pos == len) {
      num2++;
      return;
    }
    int c = s[pos] - 'a';
    if (child[c] == NULL) child[c] = new trie();
    child[c]->rec2(pos + 1);
  }
  int rec3() {
    int ans = min(intree1, intree2);
    for (int i = 0; i < 26; i++)
      if (child[i] != NULL) ans += child[i]->rec3();
    vector<int> v1, v2;
    for (int i = 0; i < ind1.size(); i++) {
      int j = ind1[i];
      if (used1.find(j) == used1.end()) v1.push_back(j);
    }
    for (int i = 0; i < ind2.size(); i++) {
      int j = ind2[i];
      if (used2.find(j) == used2.end()) v2.push_back(j);
    }
    for (int i = 0; i < min(v1.size(), v2.size()); i++) {
      v.push_back(make_pair(v1[i], v2[i]));
      used1.insert(v1[i]);
      used2.insert(v2[i]);
    }
    return ans;
  }
} root;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cur = i;
    cin >> s;
    len = s.length();
    root.rec1(0);
  }
  for (int i = 0; i < n; i++) {
    cur = i;
    cin >> s;
    len = s.length();
    root.rec2(0);
  }
  cout << root.rec3() - n << endl;
  for (int i = 0; i < n; i++)
    cout << v[i].first + 1 << " " << v[i].second + 1 << endl;
  return 0;
}
