#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int f(string s) {
  if (s[0] == '0') return false;
  for (int i = 0; i < (int)s.size(); i++)
    if (!(s[i] >= '0' && s[i] <= '9')) return false;
  int res = 0;
  for (int i = 0; i < (int)s.size(); i++) res = res * 10 + (s[i] - '0');
  return res;
}
string g(int x) {
  string res;
  while (x) {
    res += (char)('0' + x % 10);
    x /= 10;
  }
  reverse(res.begin(), res.end());
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  set<string> ttt;
  string tmp;
  int n;
  cin >> n;
  pair<string, int> a[n];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    cnt += a[i].second;
    ttt.insert(a[i].first);
  }
  while (true) {
    tmp = "";
    for (int i = 0; i < 6; i++) tmp += (char)('a' + rand() % 26);
    if (!ttt.count(tmp)) break;
  }
  set<int> x, y;
  for (int i = 1; i < cnt + 1; i++) x.insert(i);
  for (int i = cnt + 1; i < n + 1; i++) y.insert(i);
  vector<int> bad_x, bad_y;
  for (int i = 0; i < n; i++) {
    int v = f(a[i].first);
    if (v >= 1 && v <= cnt) {
      x.erase(v);
      if (a[i].second == 0) bad_x.push_back(i);
    } else if (v >= cnt + 1 && v <= n) {
      y.erase(v);
      if (a[i].second == 1) bad_y.push_back(i);
    }
  }
  vector<pair<string, string> > out;
  while ((int)bad_x.size() + (int)bad_y.size()) {
    if ((int)bad_x.size() > 0 && (int)y.size() == 0 && (int)bad_y.size() > 0 &&
        (int)x.size() == 0) {
      if ((int)bad_x.size() > 0) {
        out.push_back({a[bad_x.back()].first, tmp});
        x.insert(f(a[bad_x.back()].first));
        a[bad_x.back()].first = tmp;
        bad_x.pop_back();
      } else {
        out.push_back({a[bad_y.back()].first, tmp});
        y.insert(f(a[bad_y.back()].first));
        a[bad_y.back()].first = tmp;
        bad_y.pop_back();
      }
    } else {
      if ((int)bad_x.size() > 0 && (int)y.size() > 0) {
        int p = bad_x.back();
        bad_x.pop_back();
        string v = g(*y.begin());
        y.erase(y.begin());
        x.insert(f(a[p].first));
        out.push_back({a[p].first, v});
        a[p].first = v;
      } else if ((int)bad_y.size() > 0 && (int)x.size() > 0) {
        int p = bad_y.back();
        bad_y.pop_back();
        string v = g(*x.begin());
        x.erase(x.begin());
        y.insert(f(a[p].first));
        out.push_back({a[p].first, v});
        a[p].first = v;
      } else {
        assert(false);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int v = f(a[i].first);
    if (v >= 1 && v <= cnt && a[i].second == 1 ||
        v >= cnt + 1 && v <= n && a[i].second == 0)
      continue;
    else {
      if (a[i].second == 1) {
        string v = g(*x.begin());
        x.erase(x.begin());
        out.push_back({a[i].first, v});
      } else {
        string v = g(*y.begin());
        y.erase(y.begin());
        out.push_back({a[i].first, v});
      }
    }
  }
  cout << (int)out.size() << "\n";
  for (auto it : out) cout << "move " << it.first << " " << it.second << "\n";
  return 0;
}
