Problem: The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.

Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.

Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests.

Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.

The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.

Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run:

  * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; 
  * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. 

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests.

n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.

Output

In the first line print the minimum number of lines in Vladimir's script file.

After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.

Examples

Input

5
01 0
2 1
2extra 0
3 1
99 0


Output

4
move 3 1
move 01 5
move 2extra 4
move 99 3


Input

2
1 0
2 1


Output

3
move 1 3
move 2 1
move 3 2

Input

5
1 0
11 1
111 0
1111 1
11111 0


Output

5
move 1 5
move 11 1
move 1111 2
move 111 4
move 11111 3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn];
char S[maxn][10];
vector<int> F1, F2, F3, G1, G2, G3;
bool p[maxn];
int f[maxn];
int main() {
  int n;
  scanf("%d", &n);
  int e = 0;
  for (int t = 1; t <= n; ++t) {
    scanf("%s%d", S[t], &a[t]);
    if (a[t]) ++e;
    int len = strlen(S[t]);
    f[t] = 0;
    if (S[t][0] != '0')
      for (int i = 0; i < len; ++i) {
        if (!(S[t][i] >= 'a' && S[t][i] <= 'z')) {
          f[t] = f[t] * 10 + S[t][i] - '0';
        } else {
          f[t] = 0;
          break;
        }
      }
    if (f[t] > n) f[t] = 0;
    if (f[t] != 0) p[f[t]] = true;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 0) {
      if (f[i] == 0)
        F1.push_back(i);
      else if (f[i] <= e)
        F2.push_back(i);
    } else {
      if (f[i] == 0)
        G1.push_back(i);
      else if (f[i] > e)
        G2.push_back(i);
    }
  }
  for (int i = 1; i <= e; ++i)
    if (!p[i]) F3.push_back(i);
  for (int i = e + 1; i <= n; ++i)
    if (!p[i]) G3.push_back(i);
  int ans = F1.size() + F2.size() + G1.size() + G2.size();
  if (F3.empty() && G3.empty() &&
      !(F1.empty() && F2.empty() && G1.empty() && G2.empty()))
    ans = ans + 1;
  printf("%d\n", ans);
  while (true) {
    if (F1.empty() && F2.empty() && G1.empty() && G2.empty()) break;
    if (!F3.empty() && (!G2.empty() || !G1.empty())) {
      if (!G2.empty()) {
        int x = G2[G2.size() - 1];
        int y = F3[F3.size() - 1];
        G2.pop_back();
        F3.pop_back();
        printf("move %s %d\n", S[x], y);
        G3.push_back(f[x]);
      } else {
        int x = G1[G1.size() - 1];
        int y = F3[F3.size() - 1];
        G1.pop_back();
        F3.pop_back();
        printf("move %s %d\n", S[x], y);
      }
    } else if (!G3.empty() && (!F2.empty() || !F1.empty())) {
      if (!F2.empty()) {
        int x = F2[F2.size() - 1];
        int y = G3[G3.size() - 1];
        F2.pop_back();
        G3.pop_back();
        printf("move %s %d\n", S[x], y);
        F3.push_back(f[x]);
      } else {
        int x = F1[F1.size() - 1];
        int y = G3[G3.size() - 1];
        F1.pop_back();
        G3.pop_back();
        printf("move %s %d\n", S[x], y);
      }
    } else {
      int x = F2[F2.size() - 1];
      F2.pop_back();
      F1.push_back(x);
      F3.push_back(f[x]);
      printf("move %s znfjgd\n", S[x]);
      S[x][0] = 'z';
      S[x][1] = 'n';
      S[x][2] = 'f';
      S[x][3] = 'j';
      S[x][4] = 'g';
      S[x][5] = 'd';
    }
  }
  return 0;
}