#include <bits/stdc++.h>
using namespace std;
int n, e, kd_[100002];
struct _ {
  char s[8];
  int tp;
} s[100002];
int tr(char *s) {
  int L = strlen(s + 1);
  int u = 0;
  for (int i = 1; i <= L; i++) {
    if (i == 1 && s[i] == '0' || !isdigit(s[i])) return 0;
    u = u * 10 + s[i] - '0';
  }
  return u <= n ? u : 0;
}
set<int> sa, sb;
char sn[8];
set<int> pa, pb;
char q[100002 * 3][40];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%s%d", s[i].s + 1, &s[i].tp), e += s[i].tp;
  for (;;) {
    for (int i = 1; i <= 6; i++) {
      sn[i] = rand() % 26 + 'a';
    }
    sn[7] = '\0';
    int fl = 0;
    for (int i = 1; i <= n; i++) {
      if (strcmp(sn + 1, s[i].s + 1) == 0) {
        fl = 1;
        break;
      }
    }
    if (!fl) break;
  }
  int pn = -1;
  for (int i = 1; i <= e; i++) pa.insert(i);
  for (int i = e + 1; i <= n; i++) pb.insert(i);
  for (int i = 1; i <= n; i++) {
    int kd = tr(s[i].s);
    kd_[i] = kd;
    if (kd) {
      if (kd <= e) {
        if (s[i].tp == 0)
          sa.insert(kd), pa.erase(kd);
        else
          pa.erase(kd);
      }
      if (kd > e) {
        if (s[i].tp == 1)
          sb.insert(kd), pb.erase(kd);
        else
          pb.erase(kd);
      }
    }
  }
  int cnt = 0;
  for (; !sa.empty() || !sb.empty() || !pa.empty() || !pb.empty();) {
    if (!sa.empty() && !pb.empty()) {
      int a = *sa.begin(), b = *pb.begin();
      sprintf(q[++cnt], "move %d %d", a, b);
      sa.erase(a);
      pb.erase(b);
      pa.insert(a);
    } else if (!sb.empty() && !pa.empty()) {
      int b = *sb.begin(), a = *pa.begin();
      sprintf(q[++cnt], "move %d %d", b, a);
      sb.erase(b);
      pa.erase(a);
      pb.insert(b);
    } else if (!sa.empty()) {
      assert(!sb.empty());
      int a = *sa.begin(), b = *sb.begin();
      sprintf(q[++cnt], "move %d %s", a, sn + 1);
      pn = 1;
      sa.erase(a);
      pa.insert(a);
    } else {
      assert(sb.empty());
      if (pn == 1) {
        int t = *pb.begin();
        sprintf(q[++cnt], "move %s %d", sn + 1, t);
        pb.erase(t);
      }
      for (int i = 1; i <= n; i++)
        if (kd_[i] == 0) {
          if (s[i].tp == 1) {
            int t = *pa.begin();
            sprintf(q[++cnt], "move %s %d", s[i].s + 1, t);
            pa.erase(t);
          } else {
            int t = *pb.begin();
            sprintf(q[++cnt], "move %s %d", s[i].s + 1, t);
            pb.erase(t);
          }
        }
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) puts(q[i]);
  return 0;
}
