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 MX = 800005;
const int MC = 26;
int M[MX];
long long ans[MX];
vector<int> vec1[MX], vec2[MX];
struct dat {
  unsigned char a, b, c;
  dat(int x = 0) {
    c = x % 256;
    x /= 256;
    b = x % 256;
    x /= 256;
    a = x;
  }
  int get() { return a * 256 * 256 + b * 256 + c; }
};
inline int get(char c) { return c - 'a'; }
struct Trie {
  int n, rt;
  dat chd[MX][MC];
  int dp[MX];
  vector<int> en[MX];
  vector<int> vec[MX];
  int newNode() {
    n++;
    fill_n(chd[n], MC, 0);
    return n;
  }
  void init() {
    n = 0;
    rt = newNode();
  }
  void insert(char *s, int sn, int id) {
    int u, i, c;
    u = rt;
    for (i = 0; i < sn; i++) {
      c = get(s[i]);
      if (!(chd[u][c].get())) chd[u][c] = dat(newNode());
      u = chd[u][c].get();
      vec[u].push_back(id);
      dp[u] = i + 1;
    }
    en[u].push_back(id);
  }
} T1, T2;
char s[MX];
void dfs(int u, int v) {
  vector<int> v1, v2;
  for (int i = 0; i < T1.en[u].size(); i++) vec1[u].push_back(T1.en[u][i]);
  for (int i = 0; i < T2.en[v].size(); i++) vec2[v].push_back(T2.en[v][i]);
  for (int i = 0; i < MC; i++) {
    if (T1.chd[u][i].get() and T2.chd[v][i].get()) {
      int u1 = T1.chd[u][i].get(), v1 = T2.chd[v][i].get();
      dfs(u1, v1);
      ans[u] += ans[u1];
      for (int j = 0; j < vec1[u1].size(); j++) vec1[u].push_back(vec1[u1][j]);
      for (int j = 0; j < vec2[v1].size(); j++) vec2[v].push_back(vec2[v1][j]);
      continue;
    }
    if (T1.chd[u][i].get()) {
      int uu = T1.chd[u][i].get();
      for (int j = 0; j < T1.vec[uu].size(); j++)
        vec1[u].push_back(T1.vec[uu][j]);
    }
    if (T2.chd[v][i].get()) {
      int uu = T2.chd[v][i].get();
      for (int j = 0; j < T2.vec[uu].size(); j++)
        vec2[v].push_back(T2.vec[uu][j]);
    }
  }
  int sz1 = vec1[u].size(), sz2 = vec2[v].size();
  ans[u] += 1LL * min(sz1, sz2) * T1.dp[u];
  for (int i = 0; i < min(sz1, sz2); i++) {
    M[vec1[u].back()] = vec2[v].back();
    vec1[u].pop_back();
    vec2[v].pop_back();
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    int l = strlen(s);
    T1.insert(s, l, i + 1);
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    int l = strlen(s);
    T2.insert(s, l, i + 1);
  }
  dfs(0, 0);
  printf("%lld\n", ans[0]);
  for (int i = 1; i <= n; i++) {
    printf("%d %d\n", i, M[i]);
  }
  return 0;
}