#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
vector<string> BAD[2];
vector<int> NUM[2], OK;
int e, ile[N];
char buffer[50];
bool number(string &s, int &ans) {
  if (s[0] == '0') return false;
  for (char c : s)
    if (c < '0' || c > '9') return false;
  ans = 0;
  for (char c : s) {
    ans = ans * 10 + int(c - '0');
  }
  return true;
}
string druk(int x) {
  string s;
  int len = sprintf(buffer, "%d", x);
  for (int i = 0; i < len; i++) s.push_back(buffer[i]);
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<string, int> > tab(n);
  for (auto &p : tab) {
    cin >> p.first >> p.second;
    e += p.second;
  }
  for (int i = 0; i < n; i++) {
    auto [s, type] = tab[i];
    type ^= 1;
    int num;
    if (number(s, num) && num <= n) {
      if (type == 0 && num <= e) {
        ("OK\n");
        OK.push_back(num);
        ile[num]++;
      } else if (type == 1 && num > e) {
        ("OK\n");
        OK.push_back(num);
        ile[num]++;
      } else {
        ("NUM[%d]\n", type);
        NUM[type].push_back(num);
        ile[num]++;
      }
    } else {
      ("BAD[%d]\n", type);
      BAD[type].push_back(s);
    }
  }
  vector<string> ans;
  vector<int> puste;
  for (int i = 1; i < n + 1; i++)
    if (ile[i] == 0) puste.push_back(i);
  while ((int)OK.size() < n) {
    if (!puste.empty()) {
      int pos = puste.back();
      puste.pop_back();
      int type = 0;
      if (pos > e) type = 1;
      ("place smth in %d (type %d)\n", pos, type);
      string who;
      if (!NUM[type].empty()) {
        int x = NUM[type].back();
        NUM[type].pop_back();
        who = druk(x);
        puste.push_back(x);
        ile[x]--;
      } else if (!BAD[type].empty()) {
        who = BAD[type].back();
        BAD[type].pop_back();
      } else {
        assert(0);
      }
      OK.push_back(pos);
      ile[pos]++;
      string where = druk(pos);
      ans.push_back("move " + who + " " + where);
    } else {
      if (!NUM[0].empty()) {
        int x = NUM[0].back();
        NUM[0].pop_back();
        string where = "aldine";
        BAD[0].push_back(where);
        string who = druk(x);
        ans.push_back("move " + who + " " + where);
        ile[x]--;
        puste.push_back(x);
      }
    }
  }
  cout << ans.size() << "\n";
  for (string s : ans) cout << s << "\n";
}
