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;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcnt(s);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int n;
set<int> S10, S01, S0, S1;
set<string> Sw0, Sw1;
vector<pair<string, string> > res;
map<string, int> M;
string Vs[500005];
pair<string, int> a[500005];
bool flag[500005];
set<string> TT;
string toString(int x) {
  string res = "";
  while (x) {
    res.push_back(x % 10 + '0');
    x /= 10;
  }
  reverse((res).begin(), (res).end());
  return res;
}
string randomString() {
  string res = "aabc";
  while (TT.count(res)) {
    string temp = "";
    for (int i = 0; i < (6); ++i) {
      temp.push_back(rand() % 26 + 'a');
    }
    res = temp;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    string u = toString(i);
    Vs[i] = u;
    M[u] = i;
  }
  int num = 0;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i].first >> a[i].second;
    TT.insert(a[i].first);
    num += a[i].second;
  }
  memset(flag, 0, sizeof(flag));
  for (int i = (1); i <= (n); ++i) {
    int u = M[a[i].first];
    if (u) {
      flag[u] = 1;
      if (a[i].second == 1 && u > num) {
        S01.insert(u);
      }
      if (a[i].second == 0 && u <= num) {
        S10.insert(u);
      }
    } else {
      if (a[i].second)
        Sw1.insert(a[i].first);
      else
        Sw0.insert(a[i].first);
    }
  }
  for (int i = (1); i <= (n); ++i)
    if (!flag[i]) {
      if (i <= num)
        S1.insert(i);
      else
        S0.insert(i);
    }
  while (((long long)(S01).size()) || ((long long)(S10).size())) {
    bool have = false;
    if (((long long)(S01).size()) && ((long long)(S1).size())) {
      have = true;
      int x = *S01.begin();
      int y = *S1.begin();
      res.push_back(make_pair(Vs[x], Vs[y]));
      S01.erase(x);
      S1.erase(y);
      S0.insert(x);
    }
    if (((long long)(S10).size()) && ((long long)(S0).size())) {
      have = true;
      int x = *S10.begin();
      int y = *S0.begin();
      res.push_back(make_pair(Vs[x], Vs[y]));
      S10.erase(x);
      S0.erase(y);
      S1.insert(x);
    }
    if (!have) {
      int x = *S01.begin();
      string rdS = randomString();
      res.push_back(make_pair(Vs[x], rdS));
      S01.erase(x);
      S0.insert(x);
      Sw1.insert(rdS);
    }
  }
  while (((long long)(Sw0).size())) {
    string u = *Sw0.begin();
    int x = *S0.begin();
    res.push_back(make_pair(u, Vs[x]));
    Sw0.erase(u);
    S0.erase(x);
  }
  while (((long long)(Sw1).size())) {
    string u = *Sw1.begin();
    int x = *S1.begin();
    res.push_back(make_pair(u, Vs[x]));
    Sw1.erase(u);
    S1.erase(x);
  }
  cout << ((long long)(res).size()) << "\n";
  for (int i = 0; i < (((long long)(res).size())); ++i) {
    cout << "move " << res[i].first << " " << res[i].second << "\n";
  }
  return 0;
}