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 = int(1e5) + 5, maxv = int(8e5) + 5;
int cur = 0, match[maxn], loc[maxn][2], st[maxv * 4][2];
set<int> vec[maxv][2];
string A[maxn][2];
struct ppnode {
  int st, en, sig[2] = {0}, val[2] = {0};
  vector<int> undone[2];
  ppnode* child[26] = {NULL};
};
typedef ppnode* pnode;
inline int left(int node) { return (node << 1); }
inline int right(int node) { return (node << 1) + 1; }
void upd(int node, int L, int R, int idx, int a, int b, int type) {
  if (L == R) {
    if (type)
      vec[L][b].erase(a);
    else
      vec[L][b].insert(a);
    for (int i = 0; i < 2; i++) {
      if (vec[L][i].empty())
        st[node][i] = -1;
      else
        st[node][i] = *vec[L][i].begin();
    }
  } else {
    if (idx <= (L + R) / 2)
      upd(left(node), L, (L + R) / 2, idx, a, b, type);
    else
      upd(right(node), (L + R) / 2 + 1, R, idx, a, b, type);
    for (int i = 0; i < 2; i++)
      st[node][i] = max(st[left(node)][i], st[right(node)][i]);
  }
}
int qry(int node, int L, int R, int a, int b, int type) {
  if (a > R || b < L)
    return -1;
  else if (a <= L && R <= b) {
    return st[node][type];
  } else
    return max(qry(left(node), L, (L + R) / 2, a, b, type),
               qry(right(node), (L + R) / 2 + 1, R, a, b, type));
}
void insert(pnode& root, int sidx, int idx, int type) {
  root->sig[type]++;
  if (sidx == int(A[idx][type].size())) {
    root->val[type]++;
    root->undone[type].push_back(idx);
    return;
  }
  int ch = int(A[idx][type][sidx] - 'a');
  if (!root->child[ch]) root->child[ch] = new ppnode();
  insert(root->child[ch], sidx + 1, idx, type);
}
void pushing(pnode root) {
  root->st = ++cur;
  for (auto it : root->undone[0])
    upd(1, 0, maxv - 1, cur, it, 0, 0), loc[it][0] = cur;
  for (auto it : root->undone[1])
    upd(1, 0, maxv - 1, cur, it, 1, 0), loc[it][1] = cur;
  for (int i = 0; i < 26; i++) {
    if (root->child[i]) pushing(root->child[i]);
  }
  root->en = cur;
}
int solve(pnode root) {
  int res = min(root->sig[0], root->sig[1]);
  for (int i = 0; i < 26; i++) {
    res += (root->child[i] ? solve(root->child[i]) : 0);
  }
  int sz = min(root->sig[0], root->sig[1]);
  while (sz--) {
    int a = qry(1, 0, maxv - 1, root->st, root->en, 0),
        b = qry(1, 0, maxv - 1, root->st, root->en, 1);
    if (a == -1 || b == -1)
      break;
    else {
      match[a] = b;
      upd(1, 0, maxv - 1, loc[a][0], a, 0, 1);
      upd(1, 0, maxv - 1, loc[b][1], b, 1, 1);
    }
  }
  return res;
}
int main(void) {
  int n;
  for (int i = 0; i < 4 * maxv; i++) st[i][0] = st[i][1] = -1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> A[i][0];
  for (int i = 0; i < n; i++) cin >> A[i][1];
  pnode root = new ppnode();
  for (int i = 0; i < n; i++) {
    insert(root, 0, i, 0);
    insert(root, 0, i, 1);
  }
  pushing(root);
  int res = solve(root);
  printf("%d\n", res - n);
  for (int i = 0; i < n; i++) printf("%d %d\n", i + 1, match[i] + 1);
}