#include <bits/stdc++.h>
const int MAX_N = 1e5 + 5;
const int ANS_SIZE = 25;
const int BUF_SIZE = 4 * MAX_N * ANS_SIZE;
const int MAX_M = 7;
int n, e, k[MAX_N], q[MAX_N], ans;
char s[MAX_N][MAX_M], tmp[MAX_M], _buffer[BUF_SIZE], *buffer = _buffer;
std::vector<int> misc[2], wrong[2];
std::unordered_set<int> set[2];
void gen_tmp() {
  for (int i = 0; i < MAX_M - 1; ++i)
    if (rand() % 3)
      tmp[i] = 'a' + rand() % 26;
    else
      tmp[i] = '0' + rand() % 10;
}
int main() {
  srand(time(NULL));
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf(" %s%d", s[i], &k[i]);
    e += k[i];
  }
regen:
  gen_tmp();
  for (int i = 0; i < n; ++i)
    if (!strcmp(tmp, s[i])) goto regen;
  for (int i = 1; i <= e; ++i) set[1].insert(i);
  for (int i = e + 1; i <= n; ++i) set[0].insert(i);
  for (int i = 0; i < n; ++i) {
    int m = strlen(s[i]), num = 0;
    if (s[i][0] == '0') {
      misc[k[i]].push_back(i);
      goto skip;
    }
    for (int j = 0; j < m; ++j)
      if (s[i][j] < '0' || s[i][j] > '9') {
        misc[k[i]].push_back(i);
        goto skip;
      }
    for (int j = 0; j < m; ++j) num = num * 10 + s[i][j] - '0';
    q[i] = num;
    if (num > n)
      misc[k[i]].push_back(i);
    else if ((num <= e) != (bool)k[i]) {
      set[num <= e].erase(num);
      wrong[k[i]].push_back(i);
    } else
      set[num <= e].erase(num);
  skip:
    continue;
  }
  while (!set[1].empty() || !set[0].empty())
    if (!set[1].empty() && !wrong[1].empty()) {
      sprintf(buffer, "move %s %d\n                              ",
              s[wrong[1].back()], *set[1].begin());
      buffer += ANS_SIZE;
      ++ans;
      set[1].erase(set[1].begin());
      set[0].insert(q[wrong[1].back()]);
      wrong[1].pop_back();
    } else if (!set[0].empty() && !wrong[0].empty()) {
      sprintf(buffer, "move %s %d\n                              ",
              s[wrong[0].back()], *set[0].begin());
      buffer += ANS_SIZE;
      ++ans;
      set[0].erase(set[0].begin());
      set[1].insert(q[wrong[0].back()]);
      wrong[0].pop_back();
    } else if (!set[1].empty() && !misc[1].empty()) {
      sprintf(buffer, "move %s %d\n                              ",
              s[misc[1].back()], *set[1].begin());
      buffer += ANS_SIZE;
      ++ans;
      misc[1].pop_back();
      set[1].erase(set[1].begin());
    } else if (!set[0].empty() && !misc[0].empty()) {
      sprintf(buffer, "move %s %d\n                              ",
              s[misc[0].back()], *set[0].begin());
      buffer += ANS_SIZE;
      ++ans;
      misc[0].pop_back();
      set[0].erase(set[0].begin());
    }
  if (!wrong[1].empty()) {
    sprintf(buffer, "move %s %s\n                             ", s[wrong[1][0]],
            tmp);
    buffer += ANS_SIZE;
    ++ans;
    for (int i = 0; i + 1 < wrong[1].size(); ++i) {
      sprintf(buffer, "move %s %s\n                               ",
              s[wrong[0][i]], s[wrong[1][i]]);
      buffer += ANS_SIZE;
      ++ans;
      sprintf(buffer, "move %s %s\n                               ",
              s[wrong[1][i + 1]], s[wrong[0][i]]);
      buffer += ANS_SIZE;
      ++ans;
    }
    sprintf(buffer, "move %s %s\n                              ",
            s[wrong[0].back()], s[wrong[1].back()]);
    buffer += ANS_SIZE;
    ++ans;
    sprintf(buffer, "move %s %s\n                              ", tmp,
            s[wrong[0].back()]);
    buffer += ANS_SIZE;
    ++ans;
  }
  printf("%d\n%s\n", ans, _buffer);
  return 0;
}
