Problem: Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.

The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.

You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.

Input

First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days.

Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.

The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.

Output

Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.

Examples

Input

ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler


Output

ross rachel
joey rachel
joey phoebe
joey monica
joey chandler


Input

icm codeforces
1
codeforces technex


Output

icm codeforces
icm technex

Note

In first example, the killer starts with ross and rachel. 

  * After day 1, ross is killed and joey appears. 
  * After day 2, rachel is killed and phoebe appears. 
  * After day 3, phoebe is killed and monica appears. 
  * After day 4, monica is killed and chandler appears. 

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

public class Main {

    FastScanner scanner = new FastScanner();

    private void calc() {
        String[] names = new String[2];
        names[0] = scanner.next();
        names[1] = scanner.next();
        sout(names[0] + " " + names[1]);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            String killed = scanner.next();
            String stayed = scanner.next();
            if (names[0].equals(killed)) {
                names[0] = stayed;
            } else {
                names[1] = stayed;
            }
            sout(names[0] + " " + names[1]);
        }
    }

    /*
     * Main Method
     */
    public static void main(String[] args) throws Exception {
        // long s = System.currentTimeMillis();
        new Main().calc();
        // long e = System.currentTimeMillis();
        // System.out.println("Total: " + (e - s) + "ms");
    }

    /*
     * Read input
     */
    int[] rarr(int count) {
        int[] value = new int[count];
        for (int i = 0; i < count; i++) {
            value[i] = scanner.nextInt();
        }
        return value;
    }

    private static final Charset ANSII = Charset.forName("ASCII");

    int[] rstr() {
        String str = scanner.next().trim();
        ByteBuffer buf = ANSII.encode(str);
        byte[] barr = buf.array();
        int[] result = new int[barr.length];
        for (int i = 0; i < barr.length; i++) {
            result[i] = barr[i];
        }
        return result;
    }

    /*
     * Print Methods
     */
    void sout(int n) {
        sout(Integer.valueOf(n));
    }

    void sout(Collection<?> col) {
        for (Object object : col) {
            sout(object);
        }
    }

    void sout(int[] arr) {
        sout(Arrays.stream(arr).mapToObj(i -> "" + i).collect(Collectors.joining(" ")));
    }

    void sout(Object obj) {
        System.out.println(Objects.toString(obj, ""));
    }

    String toString(int[] arr) {
        byte[] buf = new byte[arr.length];
        for (int i = 0; i < arr.length; i++) {
            buf[i] = (byte) arr[i];
        }
        CharBuffer charBuffer = ANSII.decode(ByteBuffer.wrap(buf));
        return new String(charBuffer.array());
    }

    void soutAsString(int[] arr) {
        sout(toString(arr));
    }

    /*
     * Algorithms
     */
    void sort(int[] data) {
        Arrays.sort(data);
    }

    int max(int[] data) {
        return Arrays.stream(data).max().orElse(Integer.MIN_VALUE);
    }

    int min(int[] data) {
        return Arrays.stream(data).min().orElse(Integer.MIN_VALUE);
    }

    int maxIndex(int[] data) {
        int index = 0;
        int m = data[0];
        for (int i = 1; i < data.length; i++) {
            if (m < data[i]) {
                m = data[i];
                index = i;
            }
        }
        return index;
    }

    int[] toArray(List<Integer> lst) {
        int[] ans = new int[lst.size()];
        for (int i = 0; i < ans.length; i++) {
            ans[i] = lst.get(i);
        }
        return ans;
    }

}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }
}