#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void upd1(T& a, T b) {
  a > b ? a = b : 0;
}
template <class T>
inline void upd2(T& a, T b) {
  a < b ? a = b : 0;
}
struct ano {
  operator unsigned long long() {
    unsigned long long x = 0, y = 0, c = getchar();
    while (c < 48) y = c == 45, c = getchar();
    while (c > 47) x = x * 10 + c - 48, c = getchar();
    return y ? -x : x;
  }
} buf;
const int N = 1e5 + 5;
map<string, int> f;
char a[7], z[N][7], ans[N][20];
bool vis[N], fin[N];
vector<int> q, c2, c4;
vector<string> c1, c3;
int n, e, t[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    sprintf(a, "%d", i);
    f[a] = i;
    scanf("%s%d", z[i], t + i);
    e += t[i];
  }
  for (int i = 1; i <= n; ++i) {
    auto j = f.find(z[i]);
    if (t[i] == 1) {
      if (f.end() == j)
        c1.push_back(z[i]);
      else {
        int k = j->second;
        if (k > e)
          c2.push_back(k), vis[k] = 1;
        else
          fin[k] = 1;
      }
    } else {
      if (f.end() == j)
        c3.push_back(z[i]);
      else {
        int k = j->second;
        if (k <= e)
          c4.push_back(k), vis[k] = 1;
        else
          fin[k] = 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!fin[i] && !vis[i]) q.push_back(i);
  int m = 0;
  if (q.empty() && c2.size()) {
    sprintf(ans[m++], "move %d 0", c2.back());
    q.push_back(c2.back());
    c2.pop_back();
    c1.push_back("0");
  }
  while (q.size()) {
    int u = q.back();
    q.pop_back();
    if (u <= e) {
      if (c2.size()) {
        sprintf(ans[m++], "move %d %d", c2.back(), u);
        q.push_back(c2.back());
        c2.pop_back();
      } else {
        sprintf(ans[m++], "move %s %d", c1.back().c_str(), u);
        c1.pop_back();
      }
    } else {
      if (c4.size()) {
        sprintf(ans[m++], "move %d %d", c4.back(), u);
        q.push_back(c4.back());
        c4.pop_back();
      } else {
        sprintf(ans[m++], "move %s %d", c3.back().c_str(), u);
        c3.pop_back();
      }
    }
  }
  printf("%d\n", m);
  for (int i = 0; i < m; ++i) puts(ans[i]);
}
