#include <bits/stdc++.h>
using namespace std;
int n, e;
bool type[100001];
string pos, ele;
string name[100001];
queue<string> qe, qr, qep, qrp, qbep, qbrp;
set<string> qepc, qrpc;
vector<string> script;
int main() {
  e = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> name[i] >> type[i];
    if (type[i] == 1) {
      e++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i <= e) {
      qepc.insert(to_string(i));
    } else {
      qrpc.insert(to_string(i));
    }
  }
  for (int i = 0; i < n; i++) {
    if (qepc.count(name[i])) {
      qepc.erase(name[i]);
      if (type[i] == 0) {
        qbrp.push(name[i]);
      }
    } else if (qrpc.count(name[i])) {
      qrpc.erase(name[i]);
      if (type[i] == 1) {
        qbep.push(name[i]);
      }
    } else if (type[i] == 1) {
      qe.push(name[i]);
    } else if (type[i] == 0) {
      qr.push(name[i]);
    }
  }
  for (auto ele : qepc) {
    qep.push(ele);
  }
  for (auto ele : qrpc) {
    qrp.push(ele);
  }
  while (qep.size() + qrp.size() + qbep.size() + qbrp.size() + qe.size() +
         qr.size()) {
    if (qbep.size() && qep.size()) {
      pos = qep.front();
      ele = qbep.front();
      qep.pop();
      qbep.pop();
      script.push_back("move " + ele + " " + pos);
      qrp.push(ele);
      continue;
    }
    if (qbrp.size() && qrp.size()) {
      pos = qrp.front();
      ele = qbrp.front();
      qrp.pop();
      qbrp.pop();
      script.push_back("move " + ele + " " + pos);
      qep.push(ele);
      continue;
    }
    if (qe.size() && qep.size()) {
      pos = qep.front();
      ele = qe.front();
      qep.pop();
      qe.pop();
      script.push_back("move " + ele + " " + pos);
      continue;
    }
    if (qr.size() && qrp.size()) {
      pos = qrp.front();
      ele = qr.front();
      qrp.pop();
      qr.pop();
      script.push_back("move " + ele + " " + pos);
      continue;
    }
    ele = qbrp.front();
    qbrp.pop();
    script.push_back("move " + ele + " zzzzz");
    qep.push(ele);
    qr.push("zzzzz");
  }
  cout << script.size() << endl;
  for (auto ele : script) {
    cout << ele << endl;
  }
  return 0;
}
