#include <bits/stdc++.h>
using namespace std;
int n;
set<int> s2, t2;
pair<string, int> a[100007];
bool isDig(char c) { return c >= '0' && c <= '9'; }
int convert(string s) {
  if (s[0] == '0') return -1;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (!isDig(s[i])) return -1;
    ans = ans * 10 + s[i] - '0';
  }
  return ans;
}
string con(int first) {
  string ans;
  while (first) {
    ans += '0' + first % 10;
    first /= 10;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
vector<pair<string, string> > ans;
int main() {
  srand('D' + 'E' + 'N' + 'I' + 'S' + 'S' + 'O' + 'N' + time(NULL));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int k1 = 0, k2 = 0;
  set<string> gg;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    gg.insert(a[i].first);
    if (a[i].second == 1)
      k1++;
    else
      k2++;
  }
  for (int i = 1; i <= k1; i++) s2.insert(i);
  for (int i = k1 + 1; i <= k1 + k2; i++) t2.insert(i);
  vector<pair<string, int> > d1, d2, w1, w2;
  for (int i = 0; i < n; i++) {
    int first = convert(a[i].first);
    if (a[i].second == 1) {
      if (first >= 1 && first <= k1) {
        s2.erase(first);
      } else if (first >= k1 + 1 && first <= k1 + k2) {
        t2.erase(first);
        d2.push_back(a[i]);
      } else
        d1.push_back(a[i]);
    } else {
      if (first >= 1 && first <= k1) {
        s2.erase(first);
        w2.push_back(a[i]);
      } else if (first >= k1 + 1 && first <= k1 + k2) {
        t2.erase(first);
      } else
        w1.push_back(a[i]);
    }
  }
  string tmp;
  while (1) {
    string hi;
    for (int i = 0; i < 6; i++) hi += (char)(rand() % 26 + 'a');
    if (gg.find(hi) == gg.end()) {
      tmp = hi;
      break;
    }
  }
  while (1) {
    if (s2.size() > 0) {
      if (d2.size()) {
        ans.push_back(make_pair(d2.back().first, con(*s2.begin())));
        t2.insert(convert(d2.back().first));
        s2.erase(s2.begin());
        d2.pop_back();
      } else {
        ans.push_back(make_pair(d1.back().first, con(*s2.begin())));
        s2.erase(s2.begin());
        d1.pop_back();
      }
    } else if (t2.size() > 0) {
      if (w2.size()) {
        ans.push_back(make_pair(w2.back().first, con(*t2.begin())));
        s2.insert(convert(w2.back().first));
        t2.erase(t2.begin());
        w2.pop_back();
      } else {
        ans.push_back(make_pair(w1.back().first, con(*t2.begin())));
        t2.erase(t2.begin());
        w1.pop_back();
      }
    } else {
      if (d2.size() == 0) break;
      ans.push_back(make_pair(d2[0].first, tmp));
      for (int i = 0; i < w2.size(); i++) {
        ans.push_back(make_pair(w2[i].first, d2[i].first));
        if (i + 1 < w2.size())
          ans.push_back(make_pair(d2[i + 1].first, w2[i].first));
        else {
          ans.push_back(make_pair(tmp, w2[i].first));
        }
      }
      break;
    }
  }
  cout << ans.size() << "\n";
  for (auto c : ans) {
    cout << "move " << c.first << ' ' << c.second << "\n";
  }
}
