Problem: The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.

Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.

Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests.

Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.

The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.

Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run:

  * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; 
  * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. 

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests.

n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.

Output

In the first line print the minimum number of lines in Vladimir's script file.

After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.

Examples

Input

5
01 0
2 1
2extra 0
3 1
99 0


Output

4
move 3 1
move 01 5
move 2extra 4
move 99 3


Input

2
1 0
2 1


Output

3
move 1 3
move 2 1
move 3 2

Input

5
1 0
11 1
111 0
1111 1
11111 0


Output

5
move 1 5
move 11 1
move 1111 2
move 111 4
move 11111 3

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public HashSet<String> a;
        public HashSet<String> b;
        public HashSet<String> alls;
        public HashSet<String> bada;
        public HashSet<String> badb;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            a = new HashSet<>();
            b = new HashSet<>();
            alls = new HashSet<>();
            bada = new HashSet<>();
            badb = new HashSet<>();
            for (int i = 0; i < n; i++) {
                String s = in.next();
                int type = in.nextInt();
                if (type == 1) a.add(s);
                else b.add(s);
                alls.add(s);
            }
            List<TaskC.Operation> res = new ArrayList<>();
            int e = a.size();
            int x = n + 1;
            while (alls.contains(String.valueOf(x))) {
                x++;
            }
            String temp = String.valueOf(x);
            boolean[] good = new boolean[n + 1];
            boolean[] free = new boolean[n + 1];
            int freea = 0, freeb = 0;
            for (int i = 1; i <= e; i++) {
                String t = String.valueOf(i);
                if (a.contains(t)) {
                    good[i] = true;
                    a.remove(t);
                } else if (b.contains(t)) {
                    badb.add(t);
                    b.remove(t);
                } else {
                    free[i] = true;
                    freea++;
                }
            }
            for (int i = e + 1; i <= n; i++) {
                String t = String.valueOf(i);
                if (b.contains(t)) {
                    good[i] = true;
                    b.remove(t);
                } else if (a.contains(t)) {
                    bada.add(t);
                    a.remove(t);
                } else {
                    free[i] = true;
                    freeb++;
                }
            }

            List<String> la = new ArrayList<>(bada), lb = new ArrayList<>(badb);
            List<String> fa = new ArrayList<>(), fb = new ArrayList<>();
            for (int i = 1; i <= e; i++) if (free[i]) fa.add(String.valueOf(i));
            for (int i = e + 1; i <= n; i++) if (free[i]) fb.add(String.valueOf(i));
            List<String> ob = new ArrayList<>(b), oa = new ArrayList<>(a);

            while (la.size() > 0 || lb.size() > 0) {
                while (fa.size() > 0 || fb.size() > 0) {
                    boolean changed = false;
                    while (fa.size() > 0 && la.size() > 0) {
                        String s;
                        res.add(new TaskC.Operation(s = la.remove(la.size() - 1), fa.remove(fa.size() - 1)));
                        fb.add(s);
                        changed = true;
                    }
                    while (fb.size() > 0 && lb.size() > 0) {
                        String s;
                        res.add(new TaskC.Operation(s = lb.remove(lb.size() - 1), fb.remove(fb.size() - 1)));
                        fa.add(s);
                        changed = true;
                    }
                    if (!changed) break;
                }

                if (lb.size() > 0) {
                    String s;
                    res.add(new TaskC.Operation(s = lb.remove(lb.size() - 1), temp));
                    ob.add(temp);
                    fa.add(s);
                } else if (la.size() > 0) {
                    String s;
                    res.add(new TaskC.Operation(s = la.remove(la.size() - 1), temp));
                    oa.add(temp);
                    fb.add(s);
                }
                temp = String.valueOf(++x);
            }

            for (int i = 0; i < fa.size(); i++) {
                res.add(new TaskC.Operation(oa.get(i), fa.get(i)));
            }
            for (int i = 0; i < fb.size(); i++) {
                res.add(new TaskC.Operation(ob.get(i), fb.get(i)));
            }


            out.println(res.size());
            for (TaskC.Operation o : res) {
                out.printf("move %s %s\n", o.from, o.to);
            }


        }

        static class Operation {
            public String from;
            public String to;

            public Operation(String from, String to) {
                this.from = from;
                this.to = to;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public String next() {
            int c;
            while (isSpaceChar(c = this.read())) {
                ;
            }

            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);

            while (!isSpaceChar(c = this.read())) {
                result.appendCodePoint(c);
            }

            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void printf(String format, Object... objects) {
            writer.printf(format, objects);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}