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>
const int MaxN = 1e5 + 50;
const int MaxAi = 1e6;
template <class t>
inline void read(t &s) {
  s = 0;
  register int f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  int buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline int lowbit(int x) { return x & (-x); }
int ch[MaxAi][26], ndn;
std::vector<int> f[MaxAi], g[MaxAi];
int to[MaxN], dep[MaxAi], bak[MaxN], n;
char s[MaxAi];
inline void insert(char *s, int opt, int idx) {
  register int pos = 0;
  if (!opt)
    f[0].push_back(idx);
  else
    g[0].push_back(idx);
  for (; *s; ++s) {
    register int d = *s - 'a';
    if (!ch[pos][d]) ch[pos][d] = ++ndn, dep[ndn] = dep[pos] + 1;
    pos = ch[pos][d];
    if (!opt)
      f[pos].push_back(idx);
    else
      g[pos].push_back(idx);
  }
}
inline bool cmp(int x, int y) { return dep[x] > dep[y]; }
int id[MaxAi];
signed main(void) {
  read(n);
  for (int i = 1; i <= n; ++i) std::scanf("%s", s), insert(s, 0, i);
  for (int i = 1; i <= n; ++i) std::scanf("%s", s), insert(s, 1, i);
  for (int i = 1; i <= ndn; ++i) id[i] = i;
  std::sort(id, id + ndn + 1, cmp);
  register int ans = 0;
  for (int i = 0; i <= ndn; ++i) {
    register int x = id[i];
    while (!f[x].empty() && !g[x].empty()) {
      while (!f[x].empty() && to[f[x].back()]) f[x].pop_back();
      while (!g[x].empty() && bak[g[x].back()]) g[x].pop_back();
      if (f[x].empty() || g[x].empty()) break;
      register int u = f[x].back(), v = g[x].back();
      f[x].pop_back(), g[x].pop_back();
      to[u] = v, bak[v] = u;
      ans += dep[x];
    }
  }
  write(ans), std::puts("");
  for (int i = 1; i <= n; ++i)
    write(i), std::putchar(32), write(to[i]), std::puts("");
  return 0;
}