#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265359;
int oneCt = 0, n;
class File {
 public:
  string name;
  int type;
  bool isNum;
  int numVal;
  File(string _name, int _type) : name(_name), type(_type), isNum(true) {
    int sz = name.size();
    string s = name;
    numVal = 0;
    if (s[0] == '0') {
      isNum = false;
    } else {
      for (int i = sz - 1, mult = 1; i >= 0; i--, mult *= 10) {
        if (s[i] >= '0' && s[i] <= '9') {
          numVal += mult * (s[i] - '0');
        } else {
          isNum = false;
        }
      }
    }
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  vector<bool> avail(n + 1, true);
  vector<File> files;
  for (int i = 0; i < n; i++) {
    int x;
    string s;
    cin >> s >> x;
    oneCt += x;
    File f(s, x);
    files.push_back(f);
  }
  vector<File> ob, zb;
  for (auto f : files) {
    if (f.isNum) {
      int nv = f.numVal;
      if (nv <= n) avail[nv] = false;
      if (nv > oneCt && f.type)
        ob.push_back(f);
      else if (!f.type && (nv <= oneCt || nv > n)) {
        zb.push_back(f);
      }
    } else if (f.type)
      ob.push_back(f);
    else
      zb.push_back(f);
  }
  vector<string> operations;
  queue<File> qob, qob2, qzb, qzb2;
  for (auto f : ob) {
    if (f.isNum && f.numVal > oneCt && f.numVal <= n) {
      qob.push(f);
    } else {
      qob2.push(f);
    }
  }
  while (qob2.size()) {
    qob.push(qob2.front());
    qob2.pop();
  }
  for (auto f : zb) {
    if (f.isNum && f.numVal <= oneCt) {
      qzb.push(f);
    } else {
      qzb2.push(f);
    }
  }
  while (qzb2.size()) {
    qzb.push(qzb2.front());
    qzb2.pop();
  }
  stack<int> oneAvail, zeroAvail;
  for (int i = 1; i <= n; i++) {
    if (i <= oneCt && avail[i])
      oneAvail.push(i);
    else if (i > oneCt && avail[i])
      zeroAvail.push(i);
  }
  while (qob.size() || qzb.size()) {
    if (qob.size() && oneAvail.size()) {
      auto f = qob.front();
      if (f.isNum && f.numVal <= n) {
        zeroAvail.push(f.numVal);
      }
      string s = "move ";
      s += f.name;
      s += " ";
      s += to_string(oneAvail.top());
      operations.push_back(s);
      qob.pop();
      oneAvail.pop();
    } else if (qzb.size() && zeroAvail.size()) {
      auto f = qzb.front();
      if (f.isNum && f.numVal <= oneCt) {
        oneAvail.push(f.numVal);
      }
      string s = "move ";
      s += f.name;
      s += " ";
      s += to_string(zeroAvail.top());
      operations.push_back(s);
      qzb.pop();
      zeroAvail.pop();
    } else {
      auto f = qob.front();
      if (f.isNum && f.numVal <= n) {
        zeroAvail.push(f.numVal);
      }
      string s = "move ";
      s += f.name;
      s += " aaaaaa";
      operations.push_back(s);
      f.name = "aaaaaa";
      f.isNum = false;
      qob.pop();
      qob.push(f);
    }
  }
  cout << operations.size() << endl;
  for (string s : operations) {
    cout << s << endl;
  }
  return 0;
}
