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;
using ll = long long;
template <typename A, typename B>
ostream &operator<<(ostream &out, pair<A, B> p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <typename A,
          typename B = typename enable_if<!is_same<A, string>::value,
                                          typename A::value_type>::type>
ostream &operator<<(ostream &out, A vector) {
  out << '{';
  string sep;
  for (B x : vector) out << sep << x, sep = ", ";
  return out << '}';
}
void dbg_print() { cerr << endl; }
template <typename A, typename... B>
void dbg_print(A a, B... b) {
  cerr << ' ' << a;
  dbg_print(b...);
}
inline int to_int(const string &s) {
  int x = 0;
  for (auto c : s) {
    x *= 10;
    x += c - '0';
  }
  return x;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int n;
  cin >> n;
  array<set<int>, 2> free_poses;
  array<set<int>, 2> bad_poses;
  array<vector<string>, 2> free_files;
  vector<int> who(n, -1);
  auto get_index = [&](const string &s) {
    bool ok = true;
    ok &= s[0] != '0';
    for (auto x : s) {
      ok &= isdigit(x);
    }
    if (!ok) return -1;
    int x = to_int(s) - 1;
    if (0 <= x && x < n) return x;
    return -1;
  };
  set<string> names;
  int pretests = 0;
  for (int i = 0; i < n; i++) {
    string name;
    int type;
    cin >> name >> type;
    names.insert(name);
    pretests += type;
    int id = get_index(name);
    if (id == -1) {
      free_files[type].push_back(name);
    } else {
      who[id] = type;
    }
  }
  for (int i = 0; i < pretests; i++) {
    if (who[i] == 1) continue;
    if (who[i] == -1) {
      free_poses[1].insert(i);
    } else {
      bad_poses[1].insert(i);
    }
  }
  for (int i = pretests; i < n; i++) {
    if (who[i] == 0) continue;
    if (who[i] == -1) {
      free_poses[0].insert(i);
    } else {
      bad_poses[0].insert(i);
    }
  }
  vector<pair<string, string>> ans;
  if (((int)((free_poses[0]).size())) + ((int)((free_poses[1]).size())) == 0 &&
      ((int)((bad_poses[0]).size())) + ((int)((bad_poses[1]).size())) > 0) {
    for (int i = 0; i < 2; i++) {
      if (!((int)((bad_poses[i]).size()))) continue;
      int who = *bad_poses[i].begin();
      bad_poses[i].erase(bad_poses[i].begin());
      string name(6, 'a');
      while (names.count(name)) {
        for (auto &x : name) {
          x = 'a' + rand() % 26;
        }
      }
      ans.emplace_back(to_string(who + 1), name);
      free_files[i ^ 1].push_back(name);
      free_poses[i].insert(who);
      break;
    }
  }
  while (true) {
    bool any = false;
    for (int i = 0; i < 2; i++) {
      if (!((int)((free_poses[i]).size())) ||
          !((int)((bad_poses[i ^ 1]).size())))
        continue;
      any = true;
      int to = *free_poses[i].begin();
      free_poses[i].erase(free_poses[i].begin());
      int from = *bad_poses[i ^ 1].begin();
      bad_poses[i ^ 1].erase(bad_poses[i ^ 1].begin());
      free_poses[i ^ 1].insert(from);
      ans.emplace_back(to_string(from + 1), to_string(to + 1));
      break;
    }
    if (!any) break;
  }
  for (int i = 0; i < 2; i++) {
    assert(((int)((free_files[i]).size())) == ((int)((free_poses[i]).size())));
    while (((int)((free_files[i]).size()))) {
      string from = free_files[i].back();
      free_files[i].pop_back();
      int pos = *free_poses[i].begin();
      free_poses[i].erase(free_poses[i].begin());
      ans.emplace_back(from, to_string(pos + 1));
    }
  }
  cout << ((int)((ans).size())) << '\n';
  for (auto [s, t] : ans) {
    cout << "move " << s << ' ' << t << '\n';
  }
}