#include <bits/stdc++.h>
using namespace std;
bool check;
char name[100010][7];
int n, one = 0, zero = 0, good = 0, len, val, num, x, y;
int type[100010], file[100010] = {0};
queue<int> readyOne, readyZero, originOne, originZero, wrongOne, wrongZero;
int checkName(char s[]) {
  len = strlen(s);
  check = false;
  for (int i = 0; i < len; i++) {
    if (s[i] == '0') {
      if (!check) return -1;
    } else if (s[i] >= '1' && s[i] <= '9')
      check = true;
    else
      return -1;
  }
  val = 0;
  for (int i = 0; i < len; i++) val = val * 10 + s[i] - '0';
  return val >= 1 && val <= n ? val : -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %d", name[i], &type[i]);
    type[i] == 1 ? one++ : zero++;
  }
  for (int i = 0; i < n; i++) {
    num = checkName(name[i]);
    if (num >= 1 && num <= n) {
      if (num <= one && type[i] == 1) {
        good++;
        file[num] = 1;
      } else if (num > one && type[i] == 0) {
        good++;
        file[num] = 1;
      } else if (type[i] == 1) {
        wrongOne.push(num);
        file[num] = -1;
      } else {
        wrongZero.push(num);
        file[num] = -1;
      }
    } else if (type[i] == 1)
      originOne.push(i);
    else
      originZero.push(i);
  }
  for (int i = 1; i <= n; i++)
    if (file[i] == 0) {
      if (i <= one)
        readyOne.push(i);
      else
        readyZero.push(i);
    }
  if (good == n)
    printf("0\n");
  else if (!originOne.empty() || !originZero.empty())
    printf("%d\n", n - good);
  else
    printf("%d\n", n - good + 1);
  while (!originOne.empty() || !originZero.empty() || !wrongOne.empty() ||
         !wrongZero.empty()) {
    check = true;
    while (!wrongOne.empty() && !readyOne.empty()) {
      x = wrongOne.front();
      y = readyOne.front();
      wrongOne.pop();
      readyOne.pop();
      readyZero.push(x);
      printf("move %d %d\n", x, y);
      check = false;
    }
    while (!wrongZero.empty() && !readyZero.empty()) {
      x = wrongZero.front();
      y = readyZero.front();
      wrongZero.pop();
      readyZero.pop();
      readyOne.push(x);
      printf("move %d %d\n", x, y);
      check = false;
    }
    if (check) {
      if (wrongOne.empty() || wrongZero.empty()) {
        while (!originOne.empty() && !readyOne.empty()) {
          x = originOne.front();
          y = readyOne.front();
          originOne.pop();
          readyOne.pop();
          printf("move %s %d\n", name[x], y);
        }
        while (!originZero.empty() && !readyZero.empty()) {
          x = originZero.front();
          y = readyZero.front();
          originZero.pop();
          readyZero.pop();
          printf("move %s %d\n", name[x], y);
        }
      } else if (readyOne.empty() && readyZero.empty()) {
        if (!wrongOne.empty() && !wrongZero.empty()) {
          x = wrongZero.front();
          wrongZero.pop();
          readyOne.push(x);
          strcpy(name[n], "temp");
          type[n] = 0;
          originZero.push(n);
          n++;
          printf("move %d temp\n", x);
        }
      }
    }
  }
  return 0;
}
