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 MAXN = 1000006;
struct tnode {
  vector<int> ds;
  tnode *ke[26];
};
typedef tnode *pnode;
pnode r1, r2, nilT;
vector<pair<int, int> > kq;
bool ok1[MAXN], ok2[MAXN];
int N, M;
char S[MAXN];
long long res;
void create(pnode &p) {
  p = new (tnode);
  for (int i = 0; i < 26; i++) p->ke[i] = nilT;
}
void init() {
  nilT = new (tnode);
  create(r1);
  create(r2);
}
void docS() {
  M = 0;
  char c = getchar();
  while (c != '\n') {
    S[++M] = c;
    c = getchar();
  }
}
void build(int po, int vt, pnode p) {
  p->ds.push_back(po);
  if (vt > M) return;
  if (p->ke[S[vt] - 'a'] == nilT) create(p->ke[S[vt] - 'a']);
  build(po, vt + 1, p->ke[S[vt] - 'a']);
}
void nhap() {
  scanf("%d\n", &N);
  for (int i = 1; i <= N; i++) {
    docS();
    build(i, 1, r1);
  }
  for (int i = 1; i <= N; i++) {
    docS();
    build(i, 1, r2);
  }
}
bool noEmpty1(vector<int> &a) {
  while (!a.empty()) {
    int t = a.back();
    if (!ok1[t])
      a.pop_back();
    else
      break;
  }
  return (!a.empty());
}
bool noEmpty2(vector<int> &a) {
  while (!a.empty()) {
    int t = a.back();
    if (!ok2[t])
      a.pop_back();
    else
      break;
  }
  return (!a.empty());
}
void dfs(pnode p1, pnode p2, int l) {
  for (int j = 0; j < 26; j++) {
    if (noEmpty1(p1->ke[j]->ds) && noEmpty2(p2->ke[j]->ds))
      dfs(p1->ke[j], p2->ke[j], l + 1);
  }
  while (1) {
    int u = -1, v = -1;
    while (!p1->ds.empty()) {
      int t = p1->ds.back();
      if (ok1[t]) {
        u = t;
        break;
      } else
        p1->ds.pop_back();
    }
    if (u == -1) break;
    while (!p2->ds.empty()) {
      int t = p2->ds.back();
      if (ok2[t]) {
        v = t;
        break;
      } else
        p2->ds.pop_back();
    }
    if (v == -1) break;
    kq.push_back(make_pair(u, v));
    p1->ds.pop_back();
    p2->ds.pop_back();
    ok1[u] = 0;
    ok2[v] = 0;
    res += l;
  }
}
void tinh() {
  res = 0;
  memset(ok1, 1, sizeof(ok1));
  memset(ok2, 1, sizeof(ok2));
  dfs(r1, r2, 0);
  cout << res << endl;
  for (int i = 0; i < N; i++) printf("%d %d\n", kq[i].first, kq[i].second);
}
int main() {
  init();
  nhap();
  tinh();
  fclose(stdin);
  fclose(stdout);
  return 0;
}