#include <bits/stdc++.h>
using namespace std;
int next() {
  int x;
  cin >> x;
  return x;
}
long long lnext() {
  long long x;
  cin >> x;
  return x;
}
int main() {
  cout.precision(20);
  ios_base::sync_with_stdio(false);
  int n = next();
  set<string> name[2];
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int type = next();
    name[type].insert(s);
  }
  string fakename = "aaaaaa";
  while (name[0].count(fakename) || name[1].count(fakename)) {
    fakename = "";
    for (int i = 0; i < 6; i++) fakename += (char)('a' + rand() % 26);
  }
  int k = name[1].size();
  set<string> free[2];
  set<string> block[2];
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    int type = i <= k;
    if (name[type ^ 1].count(s))
      block[type].insert(s);
    else if (!name[type].count(s))
      free[type].insert(s);
    else
      name[type].erase(s);
  }
  vector<pair<string, string>> answ;
  while (name[0].size() || name[1].size()) {
    if (block[0].size() && free[1].size()) {
      answ.emplace_back(*block[0].begin(), *free[1].begin());
      free[0].insert(*block[0].begin());
      name[1].erase(*block[0].begin());
      block[0].erase(block[0].begin());
      free[1].erase(free[1].begin());
    } else {
      if (block[1].size() && free[0].size()) {
        answ.emplace_back(*block[1].begin(), *free[0].begin());
        free[1].insert(*block[1].begin());
        name[0].erase(*block[1].begin());
        block[1].erase(block[1].begin());
        free[0].erase(free[0].begin());
      } else {
        if (block[0].size() || block[1].size()) {
          int type = block[0].size() ? 0 : 1;
          answ.emplace_back(*block[type].begin(), fakename);
          name[type ^ 1].erase(*block[type].begin());
          name[type ^ 1].insert(fakename);
          free[type].insert(*block[type].begin());
          block[type].erase(*block[type].begin());
        } else {
          int type = name[0].size() ? 0 : 1;
          answ.emplace_back(*name[type].begin(), *free[type].begin());
          free[type].erase(*free[type].begin());
          name[type].erase(*name[type].begin());
        }
      }
    }
  }
  cout << answ.size() << "\n";
  for (auto p : answ) cout << "move " << p.first << " " << p.second << "\n";
}
