#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &first, T2 second) {
  if (first > second) first = second;
}
template <typename T1, typename T2>
inline void chkmax(T1 &first, T2 second) {
  if (first < second) first = second;
}
const string FILENAME = "input";
const int MAXN = 1e6 + 1;
int n, cnt;
set<string> cool, que;
vector<pair<string, bool>> arr;
queue<int> A[3];
set<int> B[2];
string bin;
string res[MAXN];
vector<pair<string, string>> ans;
int main() {
  srand(time(0));
  ios::sync_with_stdio(0);
  srand(time(0));
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string s = "";
    int k = i;
    while (k) {
      s += char('0' + k % 10);
      k /= 10;
    }
    reverse(s.begin(), s.end());
    res[i] = s;
    cool.insert(s);
  }
  arr.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first >> arr[i].second;
    if (arr[i].second) ++cnt;
  }
  for (int i = 1; i <= n; ++i) {
    if (i <= cnt) {
      B[0].insert(i);
    } else {
      B[1].insert(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (cool.count(arr[i].first)) {
      int j = atoi(arr[i].first.c_str());
      if ((j <= cnt && arr[i].second) || (j > cnt && !arr[i].second)) {
        B[!arr[i].second].erase(j);
      } else {
        B[arr[i].second].erase(j);
        A[arr[i].second].push(i);
      }
    } else {
      A[2].push(i);
    }
  }
  while (true) {
    bin = "";
    for (int i = 0; i < 6; ++i) {
      bin += char('a' + (rand() % 26));
    }
    bool OK = true;
    for (int i = 0; i < n; ++i) {
      if (arr[i].first == bin) {
        OK = false;
        break;
      }
    }
    if (OK) break;
  }
  while (A[0].size() || A[1].size() || A[2].size()) {
    if (B[0].size() && A[1].size()) {
      int i = A[1].front();
      A[1].pop();
      int j = *B[0].begin();
      B[0].erase(j);
      ans.push_back({arr[i].first, res[j]});
      B[1].insert(atoi(arr[i].first.c_str()));
    } else if (B[1].size() && A[0].size()) {
      int i = A[0].front();
      A[0].pop();
      int j = *B[1].begin();
      B[1].erase(j);
      ans.push_back({arr[i].first, res[j]});
      B[0].insert(atoi(arr[i].first.c_str()));
    } else if (A[2].size()) {
      int i = A[2].front();
      A[2].pop();
      if (arr[i].second) {
        int j = *B[0].begin();
        B[0].erase(j);
        ans.push_back({arr[i].first, res[j]});
      } else {
        int j = *B[1].begin();
        B[1].erase(j);
        ans.push_back({arr[i].first, res[j]});
      }
    } else {
      int a = A[0].front();
      A[0].pop();
      A[2].push(a);
      int j = atoi(arr[a].first.c_str());
      B[0].insert(j);
      ans.push_back({arr[a].first, bin});
      arr[a].first = bin;
    }
  }
  cout << ans.size() << '\n';
  for (auto i : ans) {
    cout << "move " << i.first << ' ' << i.second << '\n';
  }
}
