#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 2e5;
map<string, bool> type;
ll n;
ll e = 0;
bool good[N];
bool used[N];
ll getnum(string s) {
  if (s.empty() || (s.size() >= 2 && s.front() == '0')) {
    return -1;
  }
  ll first = 0;
  for (char c : s) {
    if (isdigit(c)) {
      first = 10 * first + c - '0';
    } else {
      return -1;
    }
  }
  if (first < 1 || first > n) {
    return -1;
  }
  return first;
}
void upd(ll i) {
  assert(1 <= i && i <= n);
  string s = to_string(i);
  good[i] = (type.count(s) && type[s] == (i <= e));
  used[i] = type.count(s);
}
vector<pair<string, string>> answer;
void makemove(string a, string b) {
  assert(type.count(a) && !type.count(b));
  answer.emplace_back(a, b);
  type[b] = type[a];
  type.erase(a);
  ll anum = getnum(a);
  ll bnum = getnum(b);
  if (anum != -1) {
    upd(anum);
  }
  if (bnum != -1) {
    upd(bnum);
  }
}
set<ll> fl;
set<ll> fr;
set<ll> wl;
set<ll> wr;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (ll i = 1; i <= n; ++i) {
    string s;
    bool tp;
    cin >> s >> tp;
    type[s] = tp;
    e += tp;
  }
  bool full = true;
  bool have = true;
  for (ll i = 1; i <= n; ++i) {
    upd(i);
    if (!good[i]) {
      full = false;
    }
    if (!used[i]) {
      have = false;
    }
  }
  if (full) {
    cout << "0\n";
    return 0;
  }
  if (have) {
    string trash = "trash";
    for (ll i = 1; i <= n; ++i) {
      if (!good[i]) {
        makemove(to_string(i), trash);
        break;
      }
    }
  }
  for (ll i = 1; i <= n; ++i) {
    if (!good[i] && used[i]) {
      if (i <= e) {
        wr.insert(i);
      } else {
        wl.insert(i);
      }
    }
    if (!used[i]) {
      if (i <= e) {
        fl.insert(i);
      } else {
        fr.insert(i);
      }
    }
  }
  while ((fl.size() && wl.size()) || (fr.size() && wr.size())) {
    if (fl.size() && wl.size()) {
      ll i = *wl.begin();
      ll j = *fl.begin();
      makemove(to_string(i), to_string(j));
      wl.erase(i);
      fl.erase(j);
      fr.insert(i);
    } else {
      ll i = *wr.begin();
      ll j = *fr.begin();
      makemove(to_string(i), to_string(j));
      wr.erase(i);
      fr.erase(j);
      fl.insert(i);
    }
  }
  assert(wl.empty() && wr.empty());
  auto cop = type;
  for (auto pa : cop) {
    string s = pa.first;
    bool tp = pa.second;
    ll num = getnum(s);
    if (num != -1) {
      continue;
    }
    if (tp == 1) {
      assert(fl.size());
      makemove(s, to_string(*fl.begin()));
      fl.erase(fl.begin());
    } else {
      assert(fr.size());
      makemove(s, to_string(*fr.begin()));
      fr.erase(fr.begin());
    }
  }
  cout << answer.size() << "\n";
  for (auto ee : answer) {
    cout << "move " << ee.first << " " << ee.second << "\n";
  }
  return 0;
}
