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 <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
inline int readChar();
template <class T = int>
inline T readInt();
template <class T>
inline void writeInt(T x, char end = 0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size = 4096;
inline int getChar() {
  static char buf[buf_size];
  static int len = 0, pos = 0;
  if (pos == len) {
    pos = 0, len = fread(buf, 1, buf_size, stdin);
  }
  if (pos == len) {
    return -1;
  }
  return buf[pos++];
}
inline int readChar() {
  int c = getChar();
  while (c <= 32) {
    c = getChar();
  }
  return c;
}
template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-') s = -1, c = getChar();
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(int x) {
  if (write_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
  write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt(T x, char end) {
  if (x < 0) writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n) s[n++] = '0' + x % 10, x /= 10;
  while (n--) writeChar(s[n]);
  if (end) writeChar(end);
}
inline void writeWord(const char *s) {
  while (*s) writeChar(*s++);
}
struct Flusher {
  ~Flusher() {
    if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
  }
} flusher;
const int MAXN = 100001;
int n;
string name[MAXN], type[MAXN];
bool used[MAXN];
bool good[MAXN];
bool inuse[MAXN * 10];
int uks;
vector<pair<string, string> > ans;
inline void adds(string a, string b) { ans.push_back(make_pair(a, b)); }
inline string getstr(int a) {
  string s;
  while (a > 0) {
    s += char('0' + a % 10);
    a /= 10;
  }
  reverse((s).begin(), (s).end());
  return s;
}
inline string getrash() {
  while (inuse[uks]) {
    uks++;
  }
  assert(uks < 1000000);
  int heh = uks;
  string a;
  for (int i = 0; i < 6; i++) {
    a += char(heh % 10 + '0');
    heh /= 10;
  }
  reverse((a).begin(), (a).end());
  uks++;
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> name[i] >> type[i];
    if (type[i] == "1") {
      cnt++;
    }
  }
  uks = n + 1;
  set<int> st, st1;
  for (int i = 1; i <= cnt; i++) {
    st.insert(i);
  }
  for (int i = cnt + 1; i <= n; i++) {
    st1.insert(i);
  }
  vector<int> g, g1, h, h1, w, w1;
  for (int i = 0; i < n; i++) {
    if (type[i] == "0") {
      if ((int)(name[i]).size() <= 6 && name[i][0] != '0') {
        int f = 0;
        bool bad = 0;
        for (int j = 0; j < (int)(name[i]).size(); j++) {
          if (name[i][j] < '0' || name[i][j] > '9') {
            bad = true;
            break;
          }
          f *= 10;
          f += name[i][j] - '0';
        }
        if (!bad) {
          inuse[f] = true;
          if (f > cnt && f <= n && !used[f]) {
            used[f] = true;
            good[i] = true;
            st1.erase(f);
            continue;
          }
        }
      }
    } else {
      if ((int)(name[i]).size() <= 6 && name[i][0] != '0') {
        int f = 0;
        bool bad = 0;
        for (int j = 0; j < (int)(name[i]).size(); j++) {
          if (name[i][j] < '0' || name[i][j] > '9') {
            bad = true;
            break;
          }
          f *= 10;
          f += name[i][j] - '0';
        }
        if (!bad) {
          inuse[f] = true;
          if (f <= cnt && f > 0 && !used[f]) {
            used[f] = true;
            good[i] = true;
            st.erase(f);
            continue;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (good[i]) {
      continue;
    }
    if (type[i] == "0") {
      if ((int)(name[i]).size() <= 6 && name[i][0] != '0') {
        int f = 0;
        bool bad = 0;
        for (int j = 0; j < (int)(name[i]).size(); j++) {
          if (name[i][j] < '0' || name[i][j] > '9') {
            bad = true;
            break;
          }
          f *= 10;
          f += name[i][j] - '0';
        }
        if (!bad) {
          inuse[f] = true;
          if (f <= cnt && f > 0 && !used[f]) {
            used[f] = true;
            h.push_back(i);
            w.push_back(f);
            st.erase(f);
          } else {
            h1.push_back(i);
          }
        } else {
          h1.push_back(i);
        }
      } else {
        h1.push_back(i);
      }
    } else {
      if ((int)(name[i]).size() <= 6 && name[i][0] != '0') {
        int f = 0;
        bool bad = 0;
        for (int j = 0; j < (int)(name[i]).size(); j++) {
          if (name[i][j] < '0' || name[i][j] > '9') {
            bad = true;
            break;
          }
          f *= 10;
          f += name[i][j] - '0';
        }
        if (!bad) {
          inuse[f] = true;
          if (f <= n && f > 0 && !used[f]) {
            used[f] = true;
            g.push_back(i);
            w1.push_back(f);
            st1.erase(f);
          } else {
            g1.push_back(i);
          }
        } else {
          g1.push_back(i);
        }
      } else {
        g1.push_back(i);
      }
    }
  }
  string trash;
  while (true) {
    if (!st.empty()) {
      if (!g.empty()) {
        int sts = *st.begin();
        adds(name[g.back()], getstr(sts));
        st.erase(sts);
        st1.insert(w1.back());
        w1.pop_back();
        g.pop_back();
      } else {
        int sts = *st.begin();
        adds(name[g1.back()], getstr(sts));
        st.erase(sts);
        g1.pop_back();
      }
      continue;
    }
    if (!st1.empty()) {
      if (!h.empty()) {
        int sts = *st1.begin();
        adds(name[h.back()], getstr(sts));
        st1.erase(sts);
        st.insert(w.back());
        w.pop_back();
        h.pop_back();
      } else {
        int sts = *st1.begin();
        adds(name[h1.back()], getstr(sts));
        st1.erase(sts);
        h1.pop_back();
      }
      continue;
    }
    if (!g.empty()) {
      string f = getrash();
      adds(name[g.back()], f);
      name[g.back()] = f;
      st1.insert(w1.back());
      w1.pop_back();
      g1.push_back(g.back());
      g.pop_back();
      continue;
    }
    if (!h.empty()) {
      string f = getrash();
      adds(name[h.back()], f);
      name[h.back()] = f;
      st.insert(w.back());
      w.pop_back();
      h1.push_back(h.back());
      h.pop_back();
      continue;
    }
    break;
  }
  assert((int)(g).size() == 0 && (int)(g1).size() == 0 &&
         (int)(h).size() == 0 && (int)(h1).size() == 0);
  cout << (int)(ans).size() << '\n';
  for (auto x : ans) {
    cout << "move" << ' ' << x.first << ' ' << x.second << '\n';
  }
  return 0;
}