#include <bits/stdc++.h>
using namespace std;
bool a[100055];
const int inf = 1e9 + 55;
int trans(string second) {
  int d = 1;
  int ans = 0;
  if (second[0] == '0') return inf;
  for (int i = second.size() - 1; i >= 0; i--) {
    if (second[i] > '9' || second[i] < '0') return inf;
    ans += d * int(second[i] - '0');
    d *= 10;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<int> busy1;
  vector<int> busy2;
  vector<int> free1;
  vector<int> free2;
  vector<pair<string, bool> > other;
  vector<pair<string, bool> > v(n);
  int k = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    if (v[i].second) k++;
  }
  for (int i = 0; i < n; i++) {
    int t = trans(v[i].first);
    if (t <= n) {
      if (t <= k) {
        a[t] = 2;
        if (!v[i].second) busy1.push_back(t);
      } else {
        a[t] = 1;
        if (v[i].second) busy2.push_back(t);
      }
    } else {
      other.push_back(v[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!a[i]) {
      if (i <= k)
        free1.push_back(i);
      else
        free2.push_back(i);
    }
  }
  vector<pair<int, int> > ans1;
  if (free1.size() == 0 && free2.size() == 0 && (busy1.size() > 0)) {
    ans1.push_back({busy1.back(), 987654});
    other.push_back({"987654", 0});
    free1.push_back(busy1.back());
    busy1.pop_back();
  }
  for (int i = 0; i < busy1.size(); i++) {
    if (free2.size() > 0) {
      ans1.push_back({busy1[i], free2.back()});
      free1.push_back(busy1[i]);
      free2.pop_back();
    } else {
      if (free1.size() > 0) {
        ans1.push_back({busy2.back(), free1.back()});
        free1.pop_back();
        ans1.push_back({busy1[i], busy2.back()});
        busy2.pop_back();
        free1.push_back(busy1[i]);
      } else {
        ans1.push_back({busy1[i], n + 1});
        ans1.push_back({busy2.back(), busy1[i]});
        ans1.push_back({n + 1, busy2.back()});
        busy2.pop_back();
      }
    }
  }
  for (int i = 0; i < busy2.size(); i++) {
    ans1.push_back({busy2[i], free1.back()});
    free2.push_back(busy2[i]);
    free1.pop_back();
  }
  cout << ans1.size() + other.size() << endl;
  for (int i = 0; i < ans1.size(); i++)
    cout << "move " << ans1[i].first << " " << ans1[i].second << "\n";
  for (int i = 0; i < other.size(); i++) {
    if (other[i].second) {
      cout << "move " << other[i].first << " " << free1.back() << endl;
      free1.pop_back();
    } else {
      cout << "move " << other[i].first << " " << free2.back() << endl;
      free2.pop_back();
    }
  }
  return 0;
}
