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 MAX_N = 100000;
const int MAX_L = 800000;
int trie[MAX_L + 10][26], tn;
char str[MAX_L + 10];
int fa[2][MAX_L + 10];
int le[MAX_L + 10], ri[MAX_L + 10];
int seq[2][MAX_N + 10], cor[MAX_N * 2 + 10];
int sl[2], sn, dep[MAX_L + 10];
int tseq[MAX_L + 10], sn2;
int mat[MAX_N + 10], n;
long long ans;
int findFather(int* fa, int a) {
  int g;
  for (g = a; fa[g] != g; g = fa[g])
    ;
  int t;
  for (; a != g; a = t) {
    t = fa[a];
    fa[a] = g;
  }
  return g;
}
int nodes[MAX_L + 10], nxt[MAX_N * 2 + 10], nu[MAX_N * 2 + 10], en;
inline void addEdge(int f, int nn) {
  ++en;
  nu[en] = nn;
  nxt[en] = nodes[f];
  nodes[f] = en;
}
int insert() {
  int cur = 0;
  for (int i = 0; str[i] != '\0'; i++) {
    int nx = str[i] - 'a';
    if (!trie[cur][nx]) {
      trie[cur][nx] = ++tn;
      dep[trie[cur][nx]] = dep[cur] + 1;
    }
    cur = trie[cur][nx];
  }
  return cur;
}
stack<int> s;
int main() {
  scanf("%d", &n);
  for (int k = 0; k < 2; k++) {
    for (int i = 1; i <= n; i++) {
      scanf("%s", str);
      int g = insert();
      addEdge(g, k ? -i : i);
    }
  }
  s.push(0);
  while (!s.empty()) {
    int cur = s.top();
    s.pop();
    le[cur] = sn;
    tseq[++sn2] = cur;
    for (int e = nodes[cur]; e; e = nxt[e]) {
      seq[nu[e] < 0][++sl[nu[e] < 0]] = ++sn;
      cor[sn] = abs(nu[e]);
    }
    ri[cur] = sn;
    for (int i = 0; i < 26; i++) {
      if (trie[cur][i]) s.push(trie[cur][i]);
    }
  }
  for (int i = 1; i <= n + 1; i++) fa[0][i] = fa[1][i] = i;
  seq[0][n + 1] = seq[1][n + 1] = sn + 1;
  for (int i = sn2; i >= 1; i--) {
    int cur = tseq[i];
    for (int j = 0; j < 26; j++)
      if (trie[cur][j] && ri[trie[cur][j]] > ri[cur])
        ri[cur] = ri[trie[cur][j]];
    int L0 = upper_bound(seq[0] + 1, seq[0] + sl[0] + 1, le[cur]) - seq[0];
    int L1 = upper_bound(seq[1] + 1, seq[1] + sl[1] + 1, le[cur]) - seq[1];
    int p[2];
    p[0] = findFather(fa[0], L0);
    p[1] = findFather(fa[1], L1);
    while (seq[0][p[0]] <= ri[cur] && seq[1][p[1]] <= ri[cur]) {
      mat[cor[seq[0][p[0]]]] = cor[seq[1][p[1]]];
      ans += dep[cur];
      fa[0][p[0]] = p[0] + 1;
      fa[1][p[1]] = p[1] + 1;
      p[0] = findFather(fa[0], p[0]);
      p[1] = findFather(fa[1], p[1]);
    }
  }
  printf(
      "%I64d"
      "\n",
      ans);
  for (int i = 1; i <= n; i++) printf("%d %d\n", i, mat[i]);
  return 0;
}