#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, f, a[N];
string s[N];
bool done[N];
struct move1 {
  string a, b;
  move1(string x = "", string y = "") {
    a = x;
    b = y;
  }
};
vector<move1> ans;
struct node {
  string s;
  node(string a = "") { s = a; }
  bool operator<(const node a) const {
    if (a.s.size() != s.size()) return s.size() < a.s.size();
    return s < a.s;
  }
};
set<node> can;
unordered_map<string, bool> mp;
vector<int> id[2];
string tostring(int n) {
  string ret;
  while (n) ret += n % 10 + '0', n /= 10;
  reverse(ret.begin(), ret.end());
  return ret;
}
int toint(string s) {
  stringstream ss;
  ss << s;
  int ret;
  ss >> ret;
  return ret;
}
bool isless(string s) {
  int x = toint(s);
  return x <= f;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) can.insert({tostring(i)}), mp[tostring(i)] = 1;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    scanf("%d", a + i);
    a[i] ^= 1;
    f += !a[i];
  }
  for (int i = 0; i < n; i++) {
    if (can.find(s[i]) != can.end()) {
      can.erase(s[i]);
      if (!a[i] && mp[s[i]] && isless(s[i])) continue;
      if (a[i] && mp[s[i]] && !isless(s[i])) continue;
    }
    id[a[i]].push_back(i);
  }
  for (int i = 0; i < 2; i++)
    sort(id[i].rbegin(), id[i].rend(), [&](int a, int b) {
      if (mp[s[a]] && mp[s[b]]) {
        if (s[a].size() != s[b].size()) return s[a].size() < s[b].size();
        return s[a] < s[b];
      }
      return mp[s[a]];
    });
  int bad = -1;
  while (id[0].size() || id[1].size()) {
    while (id[0].size() && can.size() && isless(can.begin()->s)) {
      ans.push_back({s[id[0].back()], can.begin()->s});
      can.erase(can.begin());
      if (mp[s[id[0].back()]]) can.insert(s[id[0].back()]);
      id[0].pop_back();
    }
    while (id[1].size() && can.size() && !isless(can.rbegin()->s)) {
      ans.push_back({s[id[1].back()], can.rbegin()->s});
      can.erase(--can.end());
      if (mp[s[id[1].back()]]) can.insert(s[id[1].back()]);
      id[1].pop_back();
    }
    if (can.empty()) {
      if (id[0].size() && mp[s[id[0].back()]]) {
        can.insert(s[id[0].back()]);
        ans.push_back({s[id[0].back()], "lolol"});
        s[id[0].back()] = "lolol";
        bad = id[0].back();
        id[0].pop_back();
      } else if (id[1].size()) {
        can.insert(s[id[1].back()]);
        ans.push_back({s[id[1].back()], "lolol"});
        s[id[1].back()] = "lolol";
        bad = id[1].back();
        id[1].pop_back();
      }
    }
  }
  if (bad != -1) ans.push_back({s[bad], can.begin()->s});
  printf("%d\n", ans.size());
  for (auto i : ans) printf("move %s %s\n", i.a.c_str(), i.b.c_str());
}
