#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100505;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; }
int m[nv];
set<pair<int, string>> q, g;
deque<int> ss;
string s[nv];
int a[nv];
int inline solve() {
  ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
  ;
  int n;
  cin >> n;
  int kol = 0;
  for (int i = 0; i < n; ++i) {
    cin >> s[i] >> a[i];
    if (a[i] == 1) kol++;
  }
  int ans = n;
  for (int i = 0; i < n; ++i) {
    int ex = 0;
    int h = 0;
    if (s[i][0] == '0') ex = 1;
    for (char c : s[i]) {
      int j = (c - '0');
      if (j > 9) {
        ex = 1;
        break;
      } else {
        h = h * 10 + j;
      }
    }
    if (ex == 0 && h <= n && h > 0) {
      m[h] = 1;
    } else
      ex = 1;
    if (a[i] == 1 && ex == 0 && h <= kol && h > 0) {
      ans--;
    } else if (a[i] == 0 && ex == 0 && h > kol && h <= n) {
      ans--;
    } else {
      if (ex == 0 && h > 0) {
        if (a[i] == 1) {
          q.insert({h, s[i]});
        } else {
          g.insert({h, s[i]});
        }
      } else {
        if (a[i] == 1) {
          q.insert({inf, s[i]});
        } else {
          g.insert({inf, s[i]});
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!m[i]) ss.push_back(i);
  }
  if (ans != 0 && ss.empty()) {
    cout << ans + 1 << '\n';
    pair<int, string> u = *g.begin();
    g.erase(g.begin());
    g.insert({inf, "zzx"});
    ss.push_back(u.first);
    cout << "move " << u.second << " zzx\n";
  } else {
    cout << ans << '\n';
  }
  while (!q.empty() || !g.empty()) {
    if (!q.empty() && ss.front() <= kol) {
      m[ss.front()] = 1;
      pair<int, string> u = *q.begin();
      cout << "move " << u.second << " " << ss.front() << '\n';
      q.erase(q.begin());
      ss.pop_front();
      if (u.first != inf) {
        ss.push_back(u.first);
      }
    } else {
      m[ss.back()] = 1;
      pair<int, string> u = *g.begin();
      cout << "move " << u.second << " " << ss.back() << '\n';
      g.erase(g.begin());
      ss.pop_back();
      if (u.first != inf) {
        ss.push_front(u.first);
      }
    }
  }
  return 0;
}
int32_t main() {
  solve();
  return 0;
}
