Problem: Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of some character of the popular saga and now the teachers are busy matching pseudonyms to student names.

There are n students in a summer school. Teachers chose exactly n pseudonyms for them. Each student must get exactly one pseudonym corresponding to him. Let us determine the relevance of a pseudonym b to a student with name a as the length of the largest common prefix a and b. We will represent such value as <image>. Then we can determine the quality of matching of the pseudonyms to students as a sum of relevances of all pseudonyms to the corresponding students.

Find the matching between students and pseudonyms with the maximum quality.

Input

The first line contains number n (1 ≤ n ≤ 100 000) — the number of students in the summer school.

Next n lines contain the name of the students. Each name is a non-empty word consisting of lowercase English letters. Some names can be repeating.

The last n lines contain the given pseudonyms. Each pseudonym is a non-empty word consisting of small English letters. Some pseudonyms can be repeating.

The total length of all the names and pseudonyms doesn't exceed 800 000 characters.

Output

In the first line print the maximum possible quality of matching pseudonyms to students.

In the next n lines describe the optimal matching. Each line must have the form a b (1 ≤ a, b ≤ n), that means that the student who was number a in the input, must match to the pseudonym number b in the input.

The matching should be a one-to-one correspondence, that is, each student and each pseudonym should occur exactly once in your output. If there are several optimal answers, output any.

Examples

Input

5
gennady
galya
boris
bill
toshik
bilbo
torin
gendalf
smaug
galadriel


Output

11
4 1
2 5
1 3
5 2
3 4

Note

The first test from the statement the match looks as follows: 

  * bill  →  bilbo (lcp = 3) 
  * galya  →  galadriel (lcp = 3) 
  * gennady  →  gendalf (lcp = 3) 
  * toshik  →  torin (lcp = 2) 
  * boris  →  smaug (lcp = 0) 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n;
string a[100100], b[100100];
int sz, to[26][1000100];
vector<int> g[1001000];
int ans[100100], used[100100];
vector<pair<string, int> > va, vb;
long long res = 0;
void add(string &second, int ind) {
  int cur = 0;
  for (int i = 0; i < (int)second.size(); i++) {
    int c = second[i] - 'a';
    if (to[c][cur] == -1) {
      to[c][cur] = sz++;
    }
    cur = to[c][cur];
  }
  g[cur].push_back(ind);
}
void dfs(int v, vector<int> &a) {
  if (v == -1) return;
  if (!g[v].empty()) {
    for (__typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); it++)
      a.push_back(*it);
  }
  for (int i = 0; i < 26; i++) {
    dfs(to[i][v], a);
  }
}
vector<pair<string, int> > sort_strings(vector<pair<string, int> > v) {
  memset(to, -1, sizeof to);
  for (int i = 0; i < 1001000; i++) g[i].clear();
  sz = 1;
  for (int i = 0; i < (int)v.size(); i++) add(v[i].first, i);
  vector<int> res;
  dfs(0, res);
  vector<pair<string, int> > ans;
  for (int i = 0; i < res.size(); i++)
    ans.push_back(make_pair(v[res[i]].first, res[i]));
  return ans;
}
pair<vector<pair<int, int> >, vector<pair<int, int> > > doIt(int l1, int r1,
                                                             int l2, int r2,
                                                             int ind) {
  int i1 = l1, i2 = l2;
  while (i1 <= r1 && (int)va[i1].first.size() == ind) i1++;
  while (i2 <= r2 && (int)vb[i2].first.size() == ind) i2++;
  int first, second;
  for (first = l1, second = l2; first < i1 && second < i2; first++, second++) {
    res += ind;
    ans[va[first].second] = vb[second].second;
  }
  vector<pair<int, int> > unused_a, unused_b;
  if (first < i1) unused_a.push_back(make_pair(first, i1 - 1));
  if (second < i2) unused_b.push_back(make_pair(second, i2 - 1));
  l1 = i1;
  l2 = i2;
  if (l1 > r1 || l2 > r2) {
    if (l1 <= r1) unused_a.push_back(make_pair(l1, r1));
    if (l2 <= r2) unused_b.push_back(make_pair(l2, r2));
    while (!unused_a.empty() && !unused_b.empty()) {
      pair<int, int> x = unused_a.back();
      unused_a.pop_back();
      pair<int, int> y = unused_b.back();
      unused_b.pop_back();
      int xx, yy;
      for (xx = x.first, yy = y.first; xx <= x.second && yy <= y.second;
           xx++, yy++) {
        res += ind;
        ans[va[xx].second] = vb[yy].second;
      }
      if (xx <= x.second) unused_a.push_back(make_pair(xx, x.second));
      if (yy <= y.second) unused_b.push_back(make_pair(yy, y.second));
    }
    return make_pair(unused_a, unused_b);
  }
  for (char c = 'a'; c <= 'z'; c++) {
    if (va[i1].first[ind] != c && vb[i2].first[ind] != c) continue;
    if (va[i1].first[ind] != c) {
      int ii2 = i2;
      while (i2 <= r2 && vb[i2].first[ind] == c) i2++;
      unused_b.push_back(make_pair(ii2, i2 - 1));
    } else if (vb[i2].first[ind] != c) {
      int ii1 = i1;
      while (i1 <= r1 && va[i1].first[ind] == c) i1++;
      unused_a.push_back(make_pair(ii1, i1 - 1));
    } else {
      int ii1 = i1, ii2 = i2;
      while (i1 <= r1 && va[i1].first[ind] == c) i1++;
      while (i2 <= r2 && vb[i2].first[ind] == c) i2++;
      pair<vector<pair<int, int> >, vector<pair<int, int> > > cur =
          doIt(ii1, i1 - 1, ii2, i2 - 1, ind + 1);
      for (__typeof(cur.first.begin()) it = cur.first.begin();
           it != cur.first.end(); it++)
        unused_a.push_back(*it);
      for (__typeof(cur.second.begin()) it = cur.second.begin();
           it != cur.second.end(); it++)
        unused_b.push_back(*it);
    }
    if (i1 > r1 || i2 > r2) break;
  }
  if (i1 <= r1) unused_a.push_back(make_pair(i1, r1));
  if (i2 <= r2) unused_b.push_back(make_pair(i2, r2));
  while (!unused_a.empty() && !unused_b.empty()) {
    pair<int, int> x = unused_a.back();
    unused_a.pop_back();
    pair<int, int> y = unused_b.back();
    unused_b.pop_back();
    int xx, yy;
    for (xx = x.first, yy = y.first; xx <= x.second && yy <= y.second;
         xx++, yy++) {
      res += ind;
      ans[va[xx].second] = vb[yy].second;
    }
    if (xx <= x.second) unused_a.push_back(make_pair(xx, x.second));
    if (yy <= y.second) unused_b.push_back(make_pair(yy, y.second));
  }
  return make_pair(unused_a, unused_b);
}
void print(vector<pair<string, int> > v) {
  for (int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << endl;
  cout << "_____________________" << endl;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    getline(cin, a[i]);
    va.push_back(make_pair(a[i], i));
  }
  for (int i = 0; i < n; i++) {
    getline(cin, b[i]);
    vb.push_back(make_pair(b[i], i));
  }
  va = sort_strings(va);
  vb = sort_strings(vb);
  doIt(0, n - 1, 0, n - 1, 0);
  cout << res << endl;
  for (int i = 0; i < n; i++) {
    printf("%d %d\n", i + 1, ans[i] + 1);
  }
  return 0;
}