#include <bits/stdc++.h>
using namespace std;
int n, e;
bool type[100001];
string pos, ele;
string name[100001];
const string filler = "000000";
queue<string> toe, tor, goode, goodr, bade, badr;
set<string> efinal, rfinal;
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) {
      efinal.insert(to_string(i));
    } else {
      rfinal.insert(to_string(i));
    }
  }
  for (int i = 0; i < n; i++) {
    if (efinal.count(name[i])) {
      efinal.erase(name[i]);
      if (type[i] == 0) {
        badr.push(name[i]);
      }
    } else if (rfinal.count(name[i])) {
      rfinal.erase(name[i]);
      if (type[i] == 1) {
        bade.push(name[i]);
      }
    } else if (type[i] == 1) {
      toe.push(name[i]);
    } else if (type[i] == 0) {
      tor.push(name[i]);
    }
  }
  for (auto ele : efinal) {
    goode.push(ele);
  }
  for (auto ele : rfinal) {
    goodr.push(ele);
  }
  while (goode.size() + goodr.size() + bade.size() + badr.size() + toe.size() +
         tor.size()) {
    if (bade.size() && goode.size()) {
      pos = goode.front();
      ele = bade.front();
      goode.pop();
      bade.pop();
      script.push_back("move " + ele + " " + pos);
      goodr.push(ele);
    } else if (badr.size() && goodr.size()) {
      pos = goodr.front();
      ele = badr.front();
      goodr.pop();
      badr.pop();
      script.push_back("move " + ele + " " + pos);
      goode.push(ele);
    } else if (toe.size() && goode.size()) {
      pos = goode.front();
      ele = toe.front();
      goode.pop();
      toe.pop();
      script.push_back("move " + ele + " " + pos);
    } else if (tor.size() && goodr.size()) {
      pos = goodr.front();
      ele = tor.front();
      goodr.pop();
      tor.pop();
      script.push_back("move " + ele + " " + pos);
    } else {
      ele = badr.front();
      badr.pop();
      script.push_back("move " + ele + " " + filler);
      goode.push(ele);
      tor.push(filler);
    }
  }
  cout << script.size() << endl;
  for (auto ele : script) {
    cout << ele << endl;
  }
  return 0;
}
