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>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
template <class T>
void chkmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
void chkmax(T &a, T b) {
  if (a < b) a = b;
}
int wx[1000010], wv[1000010], tmpx[1000010], tmpy[1000010];
inline int cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(int *r, int *sa, int n, int m) {
  int *x = tmpx, *y = tmpy;
  for (int i = 0; i < m; i++) wx[i] = 0;
  for (int i = 0; i < n; i++) wx[x[i] = r[i]]++;
  for (int i = 1; i < m; i++) wx[i] += wx[i - 1];
  for (int i = n - 1; i >= 0; i--) sa[--wx[x[i]]] = i;
  for (int j = 1, p = 1; p < n; j <<= 1, m = p) {
    p = 0;
    for (int i = n - j; i < n; i++) y[p++] = i;
    for (int i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    for (int i = 0; i < n; i++) wv[i] = x[y[i]];
    for (int i = 0; i < m; i++) wx[i] = 0;
    for (int i = 0; i < n; i++) wx[wv[i]]++;
    for (int i = 1; i < m; i++) wx[i] += wx[i - 1];
    for (int i = n - 1; i >= 0; i--) sa[--wx[wv[i]]] = y[i];
    swap(x, y), p = 1, x[sa[0]] = 0;
    for (int i = 1; i < n; i++)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
  }
}
int rnk[1000010], lcp[1000010];
int r[1000010], sa[1000010];
void calc_LCP(int *r, int *sa, int n) {
  lcp[0] = 0;
  for (int i = 0; i < n; i++) rnk[sa[i]] = i;
  for (int h = 0, i = 0; i < n; i++)
    if (rnk[i] > 0) {
      int j = sa[rnk[i] - 1];
      while (r[i + h] == r[j + h]) h++;
      lcp[rnk[i]] = h;
      if (h > 0) h--;
    }
}
string Name[200010], Pseu[200010];
char s[1000010];
int pos1[200010], pos2[200010];
pair<int, int> sto[200010];
int type(pair<int, int> x) { return x.first == rnk[pos2[x.second]]; }
int t[200010];
int prv[200010], nxt[200010];
int head, tail;
int LCP[200010];
set<pair<int, int> > P;
int ans[200010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> Name[i];
  for (int i = 0; i < n; i++) cin >> Pseu[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    strcpy(s, Name[i].c_str());
    int len = strlen(s);
    pos1[i] = cnt;
    for (int j = 0; j < len; j++) r[cnt++] = s[j];
    r[cnt++] = 256 + i;
  }
  int lim = cnt;
  for (int i = 0; i < n; i++) {
    strcpy(s, Pseu[i].c_str());
    int len = strlen(s);
    pos2[i] = cnt;
    for (int j = 0; j < len; j++) r[cnt++] = s[j];
    r[cnt++] = 256 + n + i;
  }
  da(r, sa, cnt, 300 + n * 2);
  calc_LCP(r, sa, cnt);
  int cs = 0;
  for (int i = 0; i < n; i++) {
    sto[++cs] = pair<int, int>(rnk[pos1[i]], i);
    sto[++cs] = pair<int, int>(rnk[pos2[i]], i);
  }
  sort(sto + 1, sto + cs + 1);
  LCP[1] = 0;
  for (int i = 2; i <= cs; i++) {
    int Min = 1 << 30;
    for (int j = sto[i - 1].first + 1; j <= sto[i].first; j++)
      chkmin(Min, lcp[j]);
    LCP[i] = Min;
  }
  head = 0, tail = cs + 1;
  for (int i = 1; i <= cs; i++) t[i] = type(sto[i]);
  for (int i = 0; i <= cs; i++) nxt[i] = i + 1, prv[i + 1] = i;
  for (int i = 2; i <= cs; i++)
    if (t[i] != t[i - 1]) P.insert(pair<int, int>(-LCP[i], i));
  long long rlt = 0;
  while (!P.empty()) {
    set<pair<int, int> >::iterator it = P.begin();
    pair<int, int> tmp = *it;
    P.erase(it);
    rlt -= tmp.first;
    int x = tmp.second;
    int p = prv[x];
    int A = sto[x].second;
    int B = sto[p].second;
    if (t[x] == 0)
      ans[A] = B;
    else
      ans[B] = A;
    int xx = nxt[x];
    int pp = prv[p];
    if (xx != tail && t[x] != t[xx]) P.erase(pair<int, int>(-LCP[xx], xx));
    if (pp != head && t[p] != t[pp]) P.erase(pair<int, int>(-LCP[p], p));
    if (xx != tail) {
      chkmin(LCP[xx], LCP[x]);
      if (pp != head) {
        chkmin(LCP[xx], LCP[p]);
        if (t[xx] != t[pp]) P.insert(pair<int, int>(-LCP[xx], xx));
      }
    }
    prv[xx] = pp;
    nxt[pp] = xx;
  }
  cout << rlt << endl;
  for (int i = 0; i < n; i++) cout << i + 1 << ' ' << ans[i] + 1 << endl;
}