You are given an array a consisting of n integers. You have to process q queries to this array; each query is given as four numbers l, r, x and y, denoting that for every i such that l ≤ i ≤ r and ai = x you have to set ai equal to y.

Print the array after all queries are processed.

Input

The first line contains one integer n (1 ≤ n ≤ 200000) — the size of array a.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the elements of array a.

The third line contains one integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.

Then q lines follow. i-th line contains four integers l, r, x and y denoting i-th query (1 ≤ l ≤ r ≤ n, 1 ≤ x, y ≤ 100).

Output

Print n integers — elements of array a after all changes are made.

Example

Input

5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5


Output

5 2 5 4 5 
import java.io.*;
import java.util.*;

import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.sqrt;

public class KirillG_Java implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            String filename = "";
            if (!filename.isEmpty()) {
                in = new BufferedReader(new FileReader(filename + ".in"));
                out = new PrintWriter(filename + ".out");
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new KirillG_Java().run();
//        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    class DSU {
        int[] parent;
        int[] color;
        int[] anyIndexWithColor;

        DSU(int n) {
            parent = new int[n];
            color = new int[n];
            anyIndexWithColor = new int[n];
            clear();
        }

        int find(int x) {
            if (parent[x] == x) return x;
            return parent[x] = find(parent[x]);
        }

        int getActualColorOf(int col) {
            return color[find(col)];
        }

        void merge(int was, int will) {
            int vertexWas = find(anyIndexWithColor[was]);
            if (color[vertexWas] != was) return;

            int vertexWill = find(anyIndexWithColor[will]);
            if (color[vertexWill] != will) {
                color[vertexWas] = will;
                anyIndexWithColor[will] = vertexWas;
            } else {
                parent[vertexWas] = vertexWill;
            }
        }

        void clear() {
            for (int i = 0; i < parent.length; i++) {
                parent[i] = i;
                color[i] = i;
                anyIndexWithColor[i] = i;
            }
        }
    }

    int n, sqrtn, sqrtx;
    int[] a;
    DSU[] buffer;

    void initX(int x) {
        buffer[x].clear();
    }

    void RestoreX(int x) {
        for (int i = x * sqrtx; i < min(n, (sqrtx * (x + 1))); i++) {
            a[i] = buffer[x].getActualColorOf(a[i]);
        }
        initX(x);
    }

    void RestoreAll() {
        for (int cnt = 0; cnt < sqrtn; cnt++)
            RestoreX(cnt);
    }


    void AddX(int l, int r, int x, int y) {
        if (x == y)
            return;
        for (int i = 0; i * sqrtx < n; i++) {
            if (i * sqrtx >= l && (i + 1) * sqrtx - 1 <= r) {
                buffer[i].merge(x, y);
            }
        }
        int lt = l / sqrtx;
        RestoreX(lt);
        if (lt * sqrtx != l) {
            int tmp = min(r + 1, min((lt + 1) * sqrtx, a.length));
            for (int i = l; i < tmp; i++) {
                if (a[i] == x) {
                    a[i] = y;
                }
            }
        }

        int rt = r / sqrtx;
        RestoreX(rt);
        if ((rt + 1) * sqrtx - 1 != r) {
            for (int i = max(l, rt * sqrtx); i <= r; i++) {
                if (a[i] == x) {
                    a[i] = y;
                }
            }
        }
    }


    private void solve() throws IOException {
        n = readInt();
        a = readIntArray(n);
        sqrtx = (int) (sqrt((double) n) + 1);
        sqrtn = (n + sqrtx - 1) / sqrtx;

        buffer = new DSU[sqrtn];
        for (int i = 0; i < buffer.length; i++) {
            buffer[i] = new DSU(101);
        }

//        Solver solver = new Solver();
//        solver.a = a.clone();
        int m = readInt();
        for (int cnt = 0; cnt < m; cnt++) {
            int l = readInt() - 1, r = readInt() - 1, x = readInt(), y = readInt();
            AddX(l, r, x, y);
//            solver.change(l, r, x, y);
        }
        RestoreAll();
//        solver.check(a);
        for (int i = 0; i < n; i++) {
            out.print(a[i]);
            out.print(" ");
        }
        out.println();
    }

    class Solver {
        int[] a;

        void change(int l, int r, int x, int y) {
            for (int i = l; i <= r; i++) {
                if (a[i] == x) a[i] = y;
            }
        }

        void check(int[] a) {
            if (!Arrays.equals(a, this.a)) throw new RuntimeException();
        }
    }
}



