#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000005;
const long long INFLL = 1000000000000000002ll;
const long long MOD = 1000000007;
inline long long min(long long a, long long b, long long c) {
  return min(min(a, b), c);
}
inline long long min(long long a, long long b, long long c, long long d) {
  return min(min(min(a, b), c), d);
}
inline long long max(long long a, long long b, long long c) {
  return max(max(a, b), c);
}
inline long long max(long long a, long long b, long long c, long long d) {
  return max(max(max(a, b), c), d);
}
int N;
queue<string> QueueE, QueueT;
set<string> FreeE, FreeT, IsE, IsT;
vector<string> CE, CT;
string tostr(int n) {
  string ret = "";
  while (n) {
    ret += (char)(n % 10 + '0');
    n /= 10;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  int e = 0;
  for (int i = (1); i <= (N); i++) {
    int t;
    string s;
    cin >> s >> t;
    if (t == 1)
      e++, CE.push_back(s);
    else
      CT.push_back(s);
  }
  for (int i = (1); i <= (e); i++) FreeE.insert(tostr(i)), IsE.insert(tostr(i));
  for (int i = (e + 1); i <= (N); i++)
    FreeT.insert(tostr(i)), IsT.insert(tostr(i));
  vector<pair<string, string>> vec;
  for (string s : CE)
    if (FreeT.find(s) != FreeT.end() && FreeE.find(s) == FreeE.end())
      QueueE.push(s);
  for (string s : CE)
    if (FreeT.find(s) == FreeT.end() && FreeE.find(s) == FreeE.end())
      QueueE.push(s);
  for (string s : CT)
    if (FreeE.find(s) != FreeE.end() && FreeT.find(s) == FreeT.end())
      QueueT.push(s);
  for (string s : CT)
    if (FreeE.find(s) == FreeE.end() && FreeT.find(s) == FreeT.end())
      QueueT.push(s);
  for (string s : CE) {
    if (FreeE.find(s) != FreeE.end()) {
      FreeE.erase(s);
      continue;
    }
    if (FreeT.find(s) != FreeT.end()) FreeT.erase(s);
  }
  for (string s : CT) {
    if (FreeT.find(s) != FreeT.end()) {
      FreeT.erase(s);
      continue;
    }
    if (FreeE.find(s) != FreeE.end()) FreeE.erase(s);
  }
  while (!QueueE.empty() || !QueueT.empty()) {
    bool moved = false;
    string s;
    if (!QueueE.empty()) {
      s = QueueE.front();
      if (!FreeE.empty()) {
        string t = *FreeE.begin();
        FreeE.erase(FreeE.begin());
        QueueE.pop();
        vec.push_back({s, t});
        moved = true;
        if (IsT.find(s) != IsT.end()) FreeT.insert(s);
      }
    }
    if (!QueueT.empty()) {
      s = QueueT.front();
      if (!FreeT.empty()) {
        string t = *FreeT.begin();
        FreeT.erase(FreeT.begin());
        QueueT.pop();
        vec.push_back({s, t});
        moved = true;
        if (IsE.find(s) != IsE.end()) FreeE.insert(s);
      }
    }
    if (!moved) {
      if (!QueueT.empty()) {
        s = QueueT.front();
        vec.push_back({s, "temp"});
        QueueT.pop();
        QueueT.push("temp");
        FreeE.insert(s);
      } else {
        s = QueueE.front();
        vec.push_back({s, "temp"});
        QueueE.pop();
        QueueE.push("temp");
        FreeT.insert(s);
      }
    }
  }
  cout << ((int)vec.size()) << "\n";
  for (pair<string, string> p : vec)
    cout << "move " << p.first << " " << p.second << "\n";
}
