#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1);
using namespace std;
const int MAX = 100 * 1000 + 10;
char buffer[10];
string name[MAX];
int type[MAX], n, e;
vector<pair<string, string> > ans;
bool read_num(const string& s, int& x) {
  x = 0;
  for (char c : s) {
    if ('0' <= c && c <= '9')
      x = x * 10 + c - '0';
    else
      return 0;
  }
  if (x == 0 && ((int)s.size()) != 1) return 0;
  if (s[0] == '0') return 0;
  return 1;
}
int get_num(const string& s) {
  int x;
  assert(read_num(s, x));
  return x;
}
void do_count(int target, int s, int e, vector<int>& inRange,
              vector<int>& inOtherRange, vector<int>& other) {
  for (int i = 0; i < (n); i++) {
    if (type[i] == target) {
      int x;
      if (read_num(name[i], x)) {
        if (s <= x && x <= e)
          inRange.push_back(i);
        else if (x > n)
          other.push_back(i);
        else
          inOtherRange.push_back(i);
      } else
        other.push_back(i);
    }
  }
  sort(inRange.begin(), inRange.end(), [](const int& a, const int& b) {
    return get_num(name[a]) < get_num(name[b]);
  });
  sort(inOtherRange.begin(), inOtherRange.end(),
       [](const int& a, const int& b) {
         return get_num(name[a]) < get_num(name[b]);
       });
}
void get_free(set<int>& S, int s, int e, vector<int>& A, vector<int>& B) {
  for (int i = (s); i <= (e); i++) S.insert(i);
  for (int x : A) {
    auto p = S.find(get_num(name[x]));
    assert(p != S.end());
    S.erase(p);
  }
  for (int x : B) {
    auto p = S.find(get_num(name[x]));
    assert(p != S.end());
    S.erase(p);
  }
}
bool work(set<int>& S, vector<int>& A, vector<int>& B, set<int>& O,
          bool yes = 0) {
  bool ret = 0;
  while (!A.empty() && !S.empty()) {
    int x = A.back();
    A.pop_back();
    ans.push_back(make_pair(name[x], to_string(*S.begin())));
    O.insert(get_num(name[x]));
    S.erase(S.begin());
    ret = 1;
  }
  if (yes) {
    while (!B.empty() && !S.empty()) {
      int x = B.back();
      B.pop_back();
      ans.push_back(make_pair(name[x], to_string(*S.begin())));
      S.erase(S.begin());
      ret = 1;
    }
  }
  return ret;
}
string get_aux() {
  set<int> S;
  for (int i = 0; i < (n); i++) {
    int x;
    if (read_num(name[i], x)) {
      S.insert(x);
    }
  }
  int i;
  for (i = n + 1;; i++)
    if (S.find(i) == S.end()) break;
  return to_string(i);
}
void work2(vector<int>& A, vector<int>& B) {
  assert(((int)A.size()) == ((int)B.size()));
  if (A.empty()) return;
  string aux = get_aux();
  int x = A.back(), y, pos = 0;
  A.pop_back();
  ans.push_back(make_pair(name[x], aux));
  while (!A.empty() || !B.empty()) {
    if (pos == 0) {
      y = B.back();
      B.pop_back();
    } else {
      y = A.back();
      A.pop_back();
    }
    ans.push_back(make_pair(name[y], name[x]));
    x = y;
    pos ^= 1;
  }
  ans.push_back(make_pair(aux, name[x]));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) {
    scanf("%s %d", buffer, type + i);
    e += type[i];
    name[i] = string(buffer);
  }
  vector<int> AinRange, AinOtherRange, Aother;
  vector<int> BinRange, BinOtherRange, Bother;
  do_count(1, 1, e, AinRange, AinOtherRange, Aother);
  do_count(0, e + 1, n, BinRange, BinOtherRange, Bother);
  set<int> up, down;
  get_free(up, 1, e, AinRange, BinOtherRange);
  get_free(down, e + 1, n, BinRange, AinOtherRange);
  while (work(up, AinOtherRange, Aother, down) ||
         work(down, BinOtherRange, Bother, up))
    ;
  work(up, AinOtherRange, Aother, down, 1);
  work(down, BinOtherRange, Bother, up, 1);
  work2(AinOtherRange, BinOtherRange);
  assert(AinOtherRange.empty());
  assert(Aother.empty());
  assert(BinOtherRange.empty());
  assert(Bother.empty());
  printf("%d\n", ((int)ans.size()));
  for (auto p : ans) printf("move %s %s\n", p.first.c_str(), p.second.c_str());
  return 0;
}
