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;
int tope = 2;
int hijo[1000000][26];
int padre[1000000];
int cuantos[1000000];
int profundidad[1000000];
vector<int> lista[1000000];
int busca(int ind) {
  while (int(lista[ind].size()) == 0) {
    for (int i = 0; i < 26; i++) {
      if (hijo[ind][i]) {
        ind = hijo[ind][i];
        break;
      }
    }
  }
  return ind;
}
int coincide(vector<int> &v) {
  int ind = 1;
  for (int i = 0; i < int(v.size()); i++) {
    if (hijo[ind][v[i]] == 0) return ind;
    ind = hijo[ind][v[i]];
  }
  return ind;
}
int arregla(vector<int> &v, int ind) {
  while (cuantos[ind] == 0) ind = padre[ind];
  return ind;
}
int inserta(vector<int> &v, int elem) {
  int ind = 1;
  cuantos[ind]++;
  for (int i = 0; i < int(v.size()); i++) {
    if (hijo[ind][v[i]] == 0) hijo[ind][v[i]] = tope++;
    padre[hijo[ind][v[i]]] = ind;
    profundidad[hijo[ind][v[i]]] = profundidad[ind] + 1;
    ind = hijo[ind][v[i]];
    cuantos[ind]++;
  }
  lista[ind].push_back(elem);
  return ind;
}
void elimina(vector<int> &v, int ind) {
  lista[ind].pop_back();
  cuantos[ind]--;
  while (ind != 1) {
    if (cuantos[ind] == 0) {
      hijo[padre[ind]][v[profundidad[ind] - 1]] = 0;
    }
    ind = padre[ind];
    cuantos[ind]--;
  }
}
int n;
vector<int> v1[200000], v2[200000];
int posicion[2000000];
int coin[2000000];
char buff[2000000];
int sol[2000000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", buff);
    int ibuff = 0;
    while (buff[ibuff]) {
      v1[i].push_back(buff[ibuff] - 'a');
      ibuff++;
    }
    posicion[i] = inserta(v1[i], i);
  }
  priority_queue<pair<int, int> > q;
  for (int i = 1; i <= n; i++) {
    scanf("%s", buff);
    int ibuff = 0;
    while (buff[ibuff]) {
      v2[i].push_back(buff[ibuff] - 'a');
      ibuff++;
    }
    coin[i] = coincide(v2[i]);
    q.push(pair<int, int>(profundidad[coin[i]], i));
  }
  int solucion = 0;
  while (not q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int x = p.second;
    int c = arregla(v2[x], coin[x]);
    if (c != coin[x]) {
      coin[x] = c;
      q.push(pair<int, int>(profundidad[coin[x]], x));
    } else {
      solucion += profundidad[coin[x]];
      int ind = busca(coin[x]);
      sol[lista[ind].back()] = x;
      elimina(v1[lista[ind].back()], ind);
    }
  }
  cout << solucion << endl;
  for (int i = 1; i <= n; i++) cout << i << " " << sol[i] << endl;
}