#include <bits/stdc++.h>
using namespace std;
int N;
int id[200000];
string S[100000];
int type[200000];
vector<int> others;
bool all_digit(string s) {
  for (char c : s) {
    if ('0' <= c && c <= '9')
      ;
    else
      return false;
  }
  return true;
}
bool used[100001];
queue<int> A, B;
queue<int> blankA, blankB;
vector<string> ops;
void moveA(string s) {
  assert(!blankA.empty());
  int x = blankA.front();
  blankA.pop();
  ops.push_back(s + " " + to_string(x));
}
void moveB(string s) {
  assert(!blankB.empty());
  int x = blankB.front();
  blankB.pop();
  ops.push_back(s + " " + to_string(x));
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  set<string> appeared;
  int e = 0;
  for (int i = 0; i < (N); i++) {
    cin >> S[i] >> type[i];
    id[i] = -1;
    e += type[i];
    if (S[i][0] == 'z') {
      appeared.insert(S[i]);
    }
  }
  mt19937 mt_rand(time(NULL));
  string hoge = "";
  do {
    hoge = "z";
    for (int _ = 0; _ < (5); _++) {
      hoge += (char)('a' + (mt_rand() % 26));
    }
  } while (appeared.find(hoge) != appeared.end());
  for (int i = 0; i < (N); i++) {
    if (S[i][0] != '0' && all_digit(S[i])) {
      int s = 0;
      for (char c : S[i]) {
        s = 10 * s + (int)(c - '0');
      }
      if (1 <= s && s <= e) {
        used[s] = true;
        id[i] = s;
        if (type[i] == 0) {
          A.push(i);
        }
      } else if (e + 1 <= s && s <= N) {
        used[s] = true;
        id[i] = s;
        if (type[i] == 1) {
          B.push(i);
        }
      } else {
        others.push_back(i);
      }
    } else {
      others.push_back(i);
    }
  }
  for (int i = 1; i <= e; i++) {
    if (used[i]) continue;
    blankA.push(i);
  }
  for (int i = e + 1; i <= N; i++) {
    if (used[i]) continue;
    blankB.push(i);
  }
  if (A.empty() && B.empty()) {
  } else {
    if (blankA.empty() && blankB.empty()) {
      int ex;
      if (A.empty()) {
        ex = B.front();
        B.pop();
        blankB.push(id[ex]);
      } else {
        ex = A.front();
        A.pop();
        blankA.push(id[ex]);
      }
      others.push_back(ex);
      ops.push_back(S[ex] + " " + hoge);
      S[ex] = hoge;
    }
    assert(!blankA.empty() || !blankB.empty());
    while (!A.empty() || !B.empty()) {
      if (!A.empty() && !blankB.empty()) {
        int x = A.front();
        moveB(S[x]);
        A.pop();
        blankA.push(id[x]);
      } else {
        assert(!B.empty() && !blankA.empty());
        int x = B.front();
        moveA(S[x]);
        B.pop();
        blankB.push(id[x]);
      }
    }
  }
  for (int o : others) {
    if (type[o] == 1)
      moveA(S[o]);
    else
      moveB(S[o]);
  }
  cout << ops.size() << "\n";
  for (string &o : ops) cout << "move " << o << "\n";
  return 0;
}
