#include <bits/stdc++.h>
using namespace std;
int printfiles(int s1, string s2) {
  cout << "move " << s1 << " " << s2 << endl;
  return 0;
}
int printfiles(string s1, int s2) {
  cout << "move " << s1 << " " << s2 << endl;
  return 0;
}
int printfiles(string s1, string s2) {
  cout << "move " << s1 << " " << s2 << endl;
  return 0;
}
int printfiles(int s1, int s2) {
  cout << "move " << s1 << " " << s2 << endl;
  return 0;
}
int n;
int check(string s) {
  if (s[0] == '0') {
    return -1;
  }
  int i, ans = 0;
  for (i = 0; i < s.length(); i++) {
    if ('0' > s[i] || s[i] > '9') return -1;
    ans *= 10;
    ans += (s[i] - '0');
  }
  if (ans > n) return -1;
  return ans;
}
string name[123456];
int typ[123456];
set<int> exset, sysset, swapsysset, swapexset;
vector<string> wrongexam, wrongsys;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  int i;
  int sumi = 0;
  for (i = 0; i < n; i++) {
    cin >> name[i] >> typ[i];
    sumi += typ[i];
  }
  for (i = 0; i < sumi; i++) {
    exset.insert(i + 1);
  }
  for (i = sumi; i < n; i++) {
    sysset.insert(i + 1);
  }
  int val, lol = n, haha = 0;
  for (i = 0; i < n; i++) {
    if (typ[i] == 1) {
      val = check(name[i]);
      if (val == -1) {
        wrongexam.push_back(name[i]);
      } else if (val > sumi) {
        sysset.erase(val);
        swapsysset.insert(val);
      } else {
        lol--;
        exset.erase(val);
      }
    } else {
      val = check(name[i]);
      if (val == -1) {
        wrongsys.push_back(name[i]);
      } else if (val <= sumi) {
        exset.erase(val);
        swapexset.insert(val);
      } else {
        haha--;
        sysset.erase(val);
      }
    }
  }
  if (lol + haha == 0) {
    cout << 0 << endl;
    return 0;
  }
  set<int>::iterator it, it1;
  if (wrongexam.empty() && wrongsys.empty()) {
    cout << lol + haha + 1 << endl;
    it = swapsysset.begin();
    sysset.insert(*it);
    printfiles(*it, "foo");
    wrongexam.push_back("foo");
    swapsysset.erase(*it);
  } else {
    cout << lol + haha << endl;
  }
  int varsys = 0, varex = 0;
  while (lol + haha) {
    lol--;
    if (!sysset.empty()) {
      it1 = sysset.begin();
      if (!swapexset.empty()) {
        it = swapexset.begin();
        printfiles(*it, *it1);
        exset.insert(*it);
        swapexset.erase(*it);
        sysset.erase(*it1);
      } else {
        printfiles(wrongsys[varsys], *it1);
        sysset.erase(*it1);
        varsys++;
      }
    } else if (!exset.empty()) {
      it1 = exset.begin();
      if (!swapsysset.empty()) {
        it = swapsysset.begin();
        printfiles(*it, *it1);
        sysset.insert(*it);
        swapsysset.erase(*it);
        exset.erase(*it1);
      } else {
        printfiles(wrongexam[varex], *it1);
        exset.erase(*it1);
        varex++;
      }
    }
  }
  return 0;
}
