#include <bits/stdc++.h>
using namespace std;
string int2str(int i) {
  if (i == 0) return "";
  string a = "1";
  a[0] = '0' + (i % 10);
  return int2str(i / 10) + a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n), c(2, 0);
  for (int i = 0; i < n; ++i) {
    cin >> s[i] >> t[i];
    ++c[t[i]];
  }
  map<string, int> m;
  for (int i = 1; i <= c[1]; ++i) m[int2str(i)] = 1;
  for (int i = c[1] + 1; i <= n; ++i) m[int2str(i)] = 0;
  queue<string> corra, corrb, oppa, oppb, rana, ranb, fria, frib;
  for (int i = 0; i < n; ++i) {
    if (t[i] == 0) {
      if (m.count(s[i]) > 0) {
        if (m[s[i]] == 0)
          corra.push(s[i]);
        else
          oppa.push(s[i]);
        m[s[i]] = 1337;
      } else
        rana.push(s[i]);
    } else {
      if (m.count(s[i]) > 0) {
        if (m[s[i]] == 1)
          corrb.push(s[i]);
        else
          oppb.push(s[i]);
        m[s[i]] = 1337;
      } else
        ranb.push(s[i]);
    }
  }
  for (int i = 1; i <= c[1]; ++i)
    if (m[int2str(i)] < 2) frib.push(int2str(i));
  for (int i = c[1] + 1; i <= n; ++i)
    if (m[int2str(i)] < 2) fria.push(int2str(i));
  if (corra.size() == c[0] && corrb.size() == c[1]) {
    cout << 0 << endl;
    return 0;
  }
  vector<string> ret;
  if (rana.empty() && ranb.empty()) {
    string q = oppa.front();
    oppa.pop();
    ret.push_back("move " + q + " bajs");
    rana.push("bajs");
    frib.push(q);
  }
  if (!fria.empty()) {
    string old = fria.front();
    fria.pop();
    while (true) {
      if (oppa.empty()) {
        fria.push(old);
        break;
      }
      string q = oppa.front();
      oppa.pop();
      ret.push_back("move " + q + " " + old);
      old = q;
      if (oppb.empty()) {
        frib.push(old);
        break;
      }
      q = oppb.front();
      oppb.pop();
      ret.push_back("move " + q + " " + old);
      old = q;
    }
  } else {
    string old = frib.front();
    frib.pop();
    while (true) {
      if (oppb.empty()) {
        frib.push(old);
        break;
      }
      string q = oppb.front();
      oppb.pop();
      ret.push_back("move " + q + " " + old);
      old = q;
      if (oppa.empty()) {
        fria.push(old);
        break;
      }
      q = oppa.front();
      oppa.pop();
      ret.push_back("move " + q + " " + old);
      old = q;
    }
  }
  while (!oppa.empty()) {
    string a = oppa.front(), b = fria.front();
    oppa.pop();
    fria.pop();
    ret.push_back("move " + a + " " + b);
    frib.push(a);
  }
  while (!oppb.empty()) {
    string a = oppb.front(), b = frib.front();
    oppb.pop();
    frib.pop();
    ret.push_back("move " + a + " " + b);
    fria.push(a);
  }
  while (!rana.empty()) {
    string a = rana.front(), b = fria.front();
    rana.pop();
    fria.pop();
    ret.push_back("move " + a + " " + b);
  }
  while (!ranb.empty()) {
    string a = ranb.front(), b = frib.front();
    ranb.pop();
    frib.pop();
    ret.push_back("move " + a + " " + b);
  }
  cout << ret.size() << endl;
  for (int i = 0; i < ret.size(); ++i) cout << ret[i] << endl;
}
