#include <bits/stdc++.h>
using namespace std;
const string exam = "z1w2e3";
string inttostr(int x) {
  string ans = "";
  while (x) ans += char('0' + x % 10), x /= 10;
  reverse(ans.begin(), ans.end());
  return ans;
}
int strtoint(const string &s) {
  int ans = 0;
  for (int i = 0; i < s.size(); i++)
    if ('a' <= s[i] && s[i] <= 'z') {
      ans = -10;
      break;
    } else
      ans += s[i] - '0', ans *= 10;
  if (inttostr(ans / 10) != s) ans = -1;
  return ans / 10;
}
set<int> fir, sec;
vector<int> l, r;
vector<pair<string, bool> > sp, sp2;
vector<pair<string, string> > ans;
void f1() {
  for (int i = 0; i < sp.size(); i++) {
    if (sp[i].second) {
      if (fir.size()) {
        ans.push_back(make_pair(sp[i].first, inttostr(*fir.begin())));
        fir.erase(fir.begin());
      } else {
        int x = l.back();
        l.pop_back();
        if (sec.size()) {
          ans.push_back(make_pair(inttostr(x), inttostr(*sec.begin())));
          sec.erase(sec.begin());
        } else {
          ans.push_back(make_pair(inttostr(x), exam));
          sp.push_back(make_pair(exam, 0));
        }
        ans.push_back(make_pair(sp[i].first, inttostr(x)));
      }
    }
  }
}
void f2() {
  for (int i = 0; i < r.size(); i++) {
    if (fir.size()) {
      ans.push_back(make_pair(inttostr(r[i]), inttostr(*fir.begin())));
      sec.insert(r[i]);
      fir.erase(fir.begin());
    } else {
      int x = l.back();
      l.pop_back();
      if (sec.size()) {
        ans.push_back(make_pair(inttostr(x), inttostr(*sec.begin())));
        sec.erase(sec.begin());
      } else {
        ans.push_back(make_pair(inttostr(x), exam));
        sp.push_back(make_pair(exam, 0));
      }
      sec.insert(r[i]);
      ans.push_back(make_pair(inttostr(r[i]), inttostr(x)));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int sch = 0;
  for (int i = 0; i < n; i++) {
    string s;
    bool t;
    cin >> s >> t;
    sch += t;
    sp.push_back(make_pair(s, t));
  }
  for (int i = 1; i <= sch; i++) fir.insert(i);
  for (int i = sch + 1; i <= n; i++) sec.insert(i);
  for (int i = 0; i < sp.size(); i++) {
    int x = strtoint(sp[i].first);
    if (0 < x && x <= sch) {
      if (sp[i].second == 0) l.push_back(x);
      fir.erase(x);
    } else if (sch < x && x <= n) {
      if (sp[i].second == 1) r.push_back(x);
      sec.erase(x);
    } else
      sp2.push_back(sp[i]);
  }
  sp = sp2;
  sp2.clear();
  if (fir.size())
    f2(), f1();
  else
    f1(), f2();
  for (int i = 0; i < sp.size(); i++)
    if (sp[i].second == 0) {
      ans.push_back(make_pair(sp[i].first, inttostr(*sec.begin())));
      sec.erase(sec.begin());
    }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << "move " << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
