#include <bits/stdc++.h>
using namespace std;
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
const long long INF = 1e9 + 7;
const long long mod = (1e9) + 7;
const int maxn = (int)225;
const long double PI = acos(-1.0);
const long double eps = 0.000000001;
mt19937 rnd(time(0));
bool is_int(string s) {
  int c = s[0] - '0';
  if (c <= 0 || c >= 10) return 0;
  for (int i = 0; i < int(s.size()); ++i) {
    c = s[i] - '0';
    if (c < 0 || c >= 10) return 0;
  }
  return 1;
}
void solve() {
  int n, kol = 0;
  cin >> n;
  vector<pair<string, int> > a(n);
  set<int> st;
  for (int i = 0; i < n; ++i) st.insert(i + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
    kol += a[i].second;
    if (is_int(a[i].first)) {
      int c = stoi(a[i].first);
      if (c <= n) st.erase(c);
    }
  }
  vector<vector<int> > one(2);
  vector<pair<string, int> > two;
  for (int i = 0; i < n; ++i) {
    if (is_int(a[i].first)) {
      int c = stoi(a[i].first);
      if (c <= n) {
        if (a[i].second && c <= kol) continue;
        if (!a[i].second && c > kol) continue;
        one[a[i].second].push_back(c);
        continue;
      }
    }
    two.push_back(a[i]);
  }
  vector<pair<string, int> > ans;
  while (int(one[0].size()) || int(one[1].size())) {
    if (!int(st.size())) {
      if (int(one[0].size())) {
        ans.push_back({to_string(one[0][0]), 999999});
        st.insert(one[0][0]), one[0][0] = 999999;
      } else {
        ans.push_back({to_string(one[1][0]), 999999});
        st.insert(one[1][0]), one[1][0] = 999999;
      }
      continue;
    }
    int v = *st.begin();
    if (v <= kol && int(one[1].size())) {
      ans.push_back({to_string(one[1].back()), v});
      st.erase(*st.begin()), st.insert(one[1].back());
      one[1].pop_back();
    }
    if (!int(st.size())) continue;
    v = *st.rbegin();
    if (v > kol && int(one[0].size())) {
      ans.push_back({to_string(one[0].back()), v});
      st.erase(*st.rbegin()), st.insert(one[0].back());
      one[0].pop_back();
    }
  }
  for (int i = 0; i < int(two.size()); ++i) {
    if (two[i].second) {
      ans.push_back({two[i].first, *st.begin()});
      st.erase(st.begin());
    } else {
      ans.push_back({two[i].first, *st.rbegin()});
      st.erase(*st.rbegin());
    }
  }
  cout << int(ans.size()) << '\n';
  for (auto &i : ans) cout << "move " << i.first << ' ' << i.second << '\n';
}
signed main() {
  GO();
  int Q = 1;
  while (Q--) {
    solve();
  }
}
