#include <bits/stdc++.h>
using namespace std;
int num(string& s) {
  if (s.front() == '0') return -1;
  int res = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] < '0' || s[i] > '9') return -1;
    res *= 10;
    res += s[i] - '0';
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  vector<string> sample, test;
  for (int i = 0; i < n; ++i) {
    string s;
    bool t;
    cin >> s >> t;
    if (t)
      sample.push_back(s);
    else
      test.push_back(s);
  }
  set<int> sn, tn;
  for (int i = 0; i < sample.size(); ++i) sn.insert(i + 1);
  for (int i = 0; i < test.size(); ++i) tn.insert(i + 1 + sample.size());
  vector<int> so(sample.size()), to(test.size());
  for (int i = 0; i < sample.size(); ++i)
    if (sn.count(num(sample[i]))) {
      so[i] = 1;
      sn.erase(num(sample[i]));
    } else if (tn.count(num(sample[i]))) {
      so[i] = 2;
      tn.erase(num(sample[i]));
    }
  for (int i = 0; i < test.size(); ++i)
    if (tn.count(num(test[i]))) {
      to[i] = 1;
      tn.erase(num(test[i]));
    } else if (sn.count(num(test[i]))) {
      to[i] = 2;
      sn.erase(num(test[i]));
    }
  bool pos = false;
  bool prog = true;
  int i1 = 0, i2 = 0;
  vector<string> oper;
  while (!pos && prog) {
    pos = true;
    prog = false;
    for (; i1 < sample.size(); ++i1) {
      if (so[i1] == 2) {
        if (sn.size()) {
          oper.push_back("move " + sample[i1] + " " + to_string(*sn.begin()));
          sn.erase(sn.begin());
          tn.insert(num(sample[i1]));
          so[i1] = 1;
          prog = true;
        } else {
          pos = false;
          break;
        }
      }
    }
    for (; i2 < test.size(); ++i2) {
      if (to[i2] == 2) {
        if (tn.size()) {
          oper.push_back("move " + test[i2] + " " + to_string(*tn.begin()));
          tn.erase(tn.begin());
          sn.insert(num(test[i2]));
          to[i2] = 1;
          prog = true;
        } else {
          pos = false;
          break;
        }
      }
    }
  }
  if (!pos) {
    if (i1 < sample.size()) {
      tn.insert(num(sample[i1]));
      oper.push_back("move " + sample[i1] + " f17917");
      sample[i1] = "f17917";
      so[i1] = 0;
    } else {
      sn.insert(num(test[i2]));
      oper.push_back("move " + test[i2] + " f17917");
      test[i2] = "f17917";
      to[i2] = 0;
    }
  }
  while (!pos) {
    pos = true;
    prog = false;
    for (; i1 < sample.size(); ++i1) {
      if (so[i1] == 2) {
        if (sn.size()) {
          oper.push_back("move " + sample[i1] + " " + to_string(*sn.begin()));
          sn.erase(sn.begin());
          tn.insert(num(sample[i1]));
          so[i1] = 1;
          prog = true;
        } else {
          pos = false;
          break;
        }
      }
    }
    for (; i2 < test.size(); ++i2) {
      if (to[i2] == 2) {
        if (tn.size()) {
          oper.push_back("move " + test[i2] + " " + to_string(*tn.begin()));
          tn.erase(tn.begin());
          sn.insert(num(test[i2]));
          to[i2] = 1;
          prog = true;
        } else {
          pos = false;
          break;
        }
      }
    }
  }
  for (int i = 0; i < sample.size(); ++i) {
    if (so[i] == 0) {
      oper.push_back("move " + sample[i] + " " + to_string(*sn.begin()));
      sn.erase(sn.begin());
    }
  }
  for (int i = 0; i < test.size(); ++i) {
    if (to[i] == 0) {
      oper.push_back("move " + test[i] + " " + to_string(*tn.begin()));
      tn.erase(tn.begin());
    }
  }
  cout << oper.size() << '\n';
  for (int i = 0; i < oper.size(); ++i) cout << oper[i] << '\n';
}
