#include <bits/stdc++.h>
using namespace std;
inline string i2s(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
int n;
char c[16];
string second[200002];
int test[200002];
vector<pair<string, string> > ans;
set<string> ss;
set<pair<int, string> > g[2];
set<string> numbers;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    numbers.insert(i2s(i));
  }
  int k = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%s %d\n", c, &test[i]);
    k += test[i];
    second[i] = c;
    ss.insert(second[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (numbers.count(second[i])) {
      int num = atoi(second[i].c_str());
      if (test[i] != (num <= k)) {
        g[test[i]].insert(make_pair(0, second[i]));
      }
      numbers.erase(second[i]);
    } else {
      g[test[i]].insert(make_pair(1, second[i]));
    }
  }
  if ((int(numbers.size())) == 0 &&
      (int(g[0].size())) + (int(g[1].size())) > 0) {
    auto t = *g[0].begin();
    string w = "";
    while (!(int(w.size())) || ss.count(w)) {
      w = "";
      for (int i = 0; i < 6; ++i) w += (rand() % 26 + 'a');
    }
    ans.push_back(make_pair(t.second, w));
    if (!t.first) {
      numbers.insert(t.second);
    }
    g[0].erase(g[0].begin());
    g[0].insert(make_pair(1, w));
  }
  while ((int(numbers.size()))) {
    auto t = *numbers.begin();
    int w = 0;
    if (atoi(t.c_str()) <= k) w = 1;
    auto cand = *g[w].begin();
    ans.push_back(make_pair(cand.second, t));
    g[w].erase(g[w].begin());
    numbers.erase(numbers.begin());
    if (!cand.first) {
      numbers.insert(cand.second);
    }
  }
  printf("%d\n", (int(ans.size())));
  for (const auto& t : ans)
    printf("move %s %s\n", t.first.c_str(), t.second.c_str());
  return 0;
}
