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 ll N = 2e5;
map<string, bool> type;
ll n;
ll e = 0;
bool good[N];
bool used[N];
ll getnum(string s) {
  if (s.empty() || (s.size() >= 2 && s.front() == '0')) {
    return -1;
  }
  ll first = 0;
  for (char c : s) {
    if (isdigit(c)) {
      first = 10 * first + c - '0';
    } else {
      return -1;
    }
  }
  if (first < 1 || first > n) {
    return -1;
  }
  return first;
}
void upd(ll i) {
  assert(1 <= i && i <= n);
  string s = to_string(i);
  good[i] = (type.count(s) && type[s] == (i <= e));
  used[i] = type.count(s);
}
vector<pair<string, string>> answer;
void makemove(string a, string b) {
  assert(type.count(a) && !type.count(b));
  answer.emplace_back(a, b);
  type[b] = type[a];
  type.erase(a);
  ll anum = getnum(a);
  ll bnum = getnum(b);
  if (anum != -1) {
    upd(anum);
  }
  if (bnum != -1) {
    upd(bnum);
  }
}
set<ll> fl;
set<ll> fr;
set<ll> wl;
set<ll> wr;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (ll i = 1; i <= n; ++i) {
    string s;
    bool tp;
    cin >> s >> tp;
    type[s] = tp;
    e += tp;
  }
  bool full = true;
  bool have = true;
  for (ll i = 1; i <= n; ++i) {
    upd(i);
    if (!good[i]) {
      full = false;
    }
    if (!used[i]) {
      have = false;
    }
  }
  if (full) {
    cout << "0\n";
    return 0;
  }
  if (have) {
    string trash = "trash";
    for (ll i = 1; i <= n; ++i) {
      if (!good[i]) {
        makemove(to_string(i), trash);
        break;
      }
    }
  }
  for (ll i = 1; i <= n; ++i) {
    if (!good[i] && used[i]) {
      if (i <= e) {
        wr.insert(i);
      } else {
        wl.insert(i);
      }
    }
    if (!used[i]) {
      if (i <= e) {
        fl.insert(i);
      } else {
        fr.insert(i);
      }
    }
  }
  while ((fl.size() && wl.size()) || (fr.size() && wr.size())) {
    if (fl.size() && wl.size()) {
      ll i = *wl.begin();
      ll j = *fl.begin();
      makemove(to_string(i), to_string(j));
      wl.erase(i);
      fl.erase(j);
      fr.insert(i);
    } else {
      ll i = *wr.begin();
      ll j = *fr.begin();
      makemove(to_string(i), to_string(j));
      wr.erase(i);
      fr.erase(j);
      fl.insert(i);
    }
  }
  assert(wl.empty() && wr.empty());
  auto cop = type;
  for (auto pa : cop) {
    string s = pa.first;
    bool tp = pa.second;
    ll num = getnum(s);
    if (num != -1) {
      continue;
    }
    if (tp == 1) {
      assert(fl.size());
      makemove(s, to_string(*fl.begin()));
      fl.erase(fl.begin());
    } else {
      assert(fr.size());
      makemove(s, to_string(*fr.begin()));
      fr.erase(fr.begin());
    }
  }
  cout << answer.size() << "\n";
  for (auto ee : answer) {
    cout << "move " << ee.first << " " << ee.second << "\n";
  }
  return 0;
}