#include <bits/stdc++.h>
using namespace std;
int toNum(string s) {
  int ans = 0;
  if (s[0] == '0') return 0x3f3f3f3f;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] < '0' || s[i] > '9') return 0x3f3f3f3f;
    ans = ans * 10 + (s[i] - '0');
  }
  return ans;
}
string toStr(int n) {
  string ans;
  while (n) ans += '0' + n % 10, n /= 10;
  reverse(ans.begin(), ans.end());
  return ans;
}
const int N = 1e5 + 10;
string s[N];
int typ[N];
int main() {
  int n;
  cin >> n;
  int L = 0;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> typ[i];
    L += typ[i];
  }
  set<string> A, B, C, D, E, F;
  for (int i = 1; i <= n; i++) {
    if (typ[i]) {
      E.insert(s[i]);
    } else {
      F.insert(s[i]);
    }
    if (i <= L) {
      D.insert(toStr(i));
    } else {
      B.insert(toStr(i));
    }
  }
  for (int i = 1; i <= n; i++) {
    if (typ[i] == 1) {
      int f = toNum(s[i]);
      if (1 <= f && f <= L) {
        E.erase(s[i]);
        D.erase(s[i]);
      }
      if (L < f && f <= n) {
        E.erase(s[i]);
        A.insert(s[i]);
        B.erase(s[i]);
      }
    } else {
      int f = toNum(s[i]);
      if (L < f && f <= n) {
        F.erase(s[i]);
        B.erase(s[i]);
      }
      if (1 <= f && f <= L) {
        F.erase(s[i]);
        C.insert(s[i]);
        D.erase(s[i]);
      }
    }
  }
  vector<pair<string, string>> ans;
  while (A.size() + B.size() + C.size() + D.size()) {
    if (E.empty() && F.empty()) {
      string f = *A.begin();
      A.erase(f);
      B.insert(f);
      ans.push_back({f, "molla"});
      f = "molla";
      E.insert(f);
      continue;
    }
    string x, y;
    if (A.size() && D.size()) {
      x = *A.begin();
      y = *D.begin();
      A.erase(x);
      D.erase(y);
      B.insert(x);
    } else if (C.size() && B.size()) {
      x = *C.begin();
      y = *B.begin();
      C.erase(x);
      B.erase(y);
      D.insert(x);
    } else if (E.size()) {
      x = *E.begin();
      y = *D.begin();
      E.erase(x);
      D.erase(y);
    } else if (F.size()) {
      x = *F.begin();
      y = *B.begin();
      F.erase(x);
      B.erase(y);
    } else {
      while (true)
        ;
    }
    ans.push_back({x, y});
  }
  cout << ans.size() << endl;
  for (auto &r : ans) {
    cout << "move " << r.first << ' ' << r.second << endl;
  }
  return 0;
}
