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;
const int N = 100500;
char buf[10];
string scan_token() {
  scanf("%s", buf);
  return buf;
}
int n;
string name[N];
bool sample[N];
int samples_cnt;
string temp_file;
set<string> all_names;
vector<pair<string, string>> ops;
vector<string> sample_holes, test_holes;
vector<int> sample_bad, test_bad;
bool try_parse(const string& s, int& num) {
  if (s.empty() || s[0] == '0') return false;
  for (char c : s)
    if (!isdigit(c)) return false;
  num = atoi(s.c_str());
  return true;
}
void fill_bad() {
  sample_bad.clear();
  test_bad.clear();
  for (int i = 0; i < n; i++) {
    int num;
    if (!try_parse(name[i], num)) continue;
    if (1 <= num && num <= samples_cnt && !sample[i]) test_bad.push_back(i);
    if (samples_cnt < num && num <= n && sample[i]) sample_bad.push_back(i);
  }
}
bool generate_temp(int p) {
  if (p == 6) return !all_names.count(temp_file);
  for (char c = 'a'; c <= 'z'; c++) {
    temp_file += c;
    if (generate_temp(p + 1)) return true;
    temp_file.pop_back();
  }
  return false;
}
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    name[i] = scan_token();
    all_names.insert(name[i]);
    int t;
    scanf("%d", &t);
    sample[i] = t == 1;
    samples_cnt += t;
  }
  generate_temp(0);
  for (int i = 1; i <= n; i++) {
    string f = to_string(i);
    if (all_names.count(f)) continue;
    if (i <= samples_cnt)
      sample_holes.push_back(f);
    else
      test_holes.push_back(f);
  }
  fill_bad();
  bool any = true;
  while (any) {
    any = false;
    if (!test_bad.empty() && !test_holes.empty()) {
      int i = test_bad.back();
      test_bad.pop_back();
      string hole = test_holes.back();
      test_holes.pop_back();
      sample_holes.push_back(name[i]);
      ops.emplace_back(name[i], hole);
      name[i] = hole;
      any = true;
    }
    if (!sample_bad.empty() && !sample_holes.empty()) {
      int i = sample_bad.back();
      sample_bad.pop_back();
      string hole = sample_holes.back();
      sample_holes.pop_back();
      test_holes.push_back(name[i]);
      ops.emplace_back(name[i], hole);
      name[i] = hole;
      any = true;
    }
  }
  for (int i = 0; i < n; i++) {
    int num;
    if (try_parse(name[i], num) && 1 <= num && num <= n) continue;
    if (sample[i]) {
      if (!sample_holes.empty()) {
        string hole = sample_holes.back();
        sample_holes.pop_back();
        ops.emplace_back(name[i], hole);
        name[i] = hole;
      }
    } else {
      if (!test_holes.empty()) {
        string hole = test_holes.back();
        test_holes.pop_back();
        ops.emplace_back(name[i], hole);
        name[i] = hole;
      }
    }
  }
  fill_bad();
  if (sample_bad.size() != test_bad.size()) throw logic_error("baaad");
  if (!sample_bad.empty()) {
    ops.emplace_back(name[sample_bad[0]], temp_file);
    for (int i = 0; i < (int)sample_bad.size(); i++) {
      ops.emplace_back(name[test_bad[i]], name[sample_bad[i]]);
      if (i + 1 < (int)sample_bad.size())
        ops.emplace_back(name[sample_bad[i + 1]], name[test_bad[i]]);
    }
    ops.emplace_back(temp_file, name[test_bad.back()]);
  }
  printf("%d\n", (int)ops.size());
  for (const auto& e : ops)
    printf("move %s %s\n", e.first.c_str(), e.second.c_str());
}
int main() {
  solve();
  (void)0;
}