/*input
5
1 2 3 4 5
2
1 4 1 2
1 4 2 3
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
const int BLOCK_SIZE = 800;
const int N = 2e5 + 5;
const int LIM = 100;
int n, nblocks;
int a[N];
int lazy[N / BLOCK_SIZE + 1][LIM + 1];
void doLazy(int id) { // L R là đầu trái và đầu phải của phần dư bên trái
int L = id * BLOCK_SIZE;
int R = min(n - 1, (id + 1) * BLOCK_SIZE - 1);
for (int i = L; i <= R; i++) {
a[i] = lazy[id][a[i]]; // thay đổi giá trị các phần tử bằng mảng lazy
}
for (int i = 1; i <= 100; i++) {
lazy[id][i] = i; // đã cập nhật xong, reset lại mảng lazy về ban đầu
}
}
void manualUpdate(int L, int R, int oval, int nval) { // L R là đầu trái và đầu phải của phần dư bên trái
int id = R / BLOCK_SIZE;
doLazy(id);
for (int i = L; i <= R; i++) {
if (a[i] == oval) {
a[i] = nval;
}
}
}
void blockUpdate(int id, int oval, int nval) {
for (int i = 1; i <= LIM; i++) {
if (lazy[id][i] == oval) {
lazy[id][i] = nval;
}
}
}
void update(int l, int r, int oval, int nval) {
int blockL = l / BLOCK_SIZE, blockR = r / BLOCK_SIZE;
if (blockL == blockR) {
manualUpdate(l, r, oval, nval);
return;
}
for (int i = blockL + 1; i < blockR; ++i) {
blockUpdate(i, oval, nval);
}
manualUpdate(l, (blockL + 1) * BLOCK_SIZE - 1, oval, nval);
manualUpdate(blockR * BLOCK_SIZE, r, oval, nval);
}
void init() {
nblocks = (n + BLOCK_SIZE - 1) / BLOCK_SIZE;
for (int i = 0; i < nblocks; i++) {
for (int j = 1; j <= 100; j++) {
lazy[i][j] = j;
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
init();
int q; cin >> q;
for (int Q = 0; Q < q; Q++) {
int l, r, oval, nval;
cin >> l >> r >> oval >> nval;
l--; r--;
update(l, r, oval, nval);
}
for (int i = 0; i < nblocks; i++) {
doLazy(i);
}
for (int i = 0; i < n; i++) {
cout << a[i] << sp;
}
cout << endl;
}
LyppbnB1dAo1CjEgMiAzIDQgNQoyCjEgNCAxIDIKMSA0IDIgMwoqLwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBzcCAnICcKI2RlZmluZSBlbmRsICdcbicKCmNvbnN0IGludCBCTE9DS19TSVpFID0gODAwOwpjb25zdCBpbnQgTiA9IDJlNSArIDU7CmNvbnN0IGludCBMSU0gPSAxMDA7CmludCBuLCBuYmxvY2tzOwppbnQgYVtOXTsKaW50IGxhenlbTiAvIEJMT0NLX1NJWkUgKyAxXVtMSU0gKyAxXTsKCnZvaWQgZG9MYXp5KGludCBpZCkgeyAvLyBMIFIgbMOgIMSR4bqndSB0csOhaSB2w6AgxJHhuqd1IHBo4bqjaSBj4bunYSBwaOG6p24gZMawIGLDqm4gdHLDoWkKICAgIGludCBMID0gaWQgKiBCTE9DS19TSVpFOwogICAgaW50IFIgPSBtaW4obiAtIDEsIChpZCArIDEpICogQkxPQ0tfU0laRSAtIDEpOwogICAgZm9yIChpbnQgaSA9IEw7IGkgPD0gUjsgaSsrKSB7CiAgICAgICAgYVtpXSA9IGxhenlbaWRdW2FbaV1dOyAvLyB0aGF5IMSR4buVaSBnacOhIHRy4buLIGPDoWMgcGjhuqduIHThu60gYuG6sW5nIG3huqNuZyBsYXp5CiAgICB9CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSAxMDA7IGkrKykgewogICAgICAgIGxhenlbaWRdW2ldID0gaTsgLy8gxJHDoyBj4bqtcCBuaOG6rXQgeG9uZywgcmVzZXQgbOG6oWkgbeG6o25nIGxhenkgduG7gSBiYW4gxJHhuqd1CiAgICB9Cn0KCnZvaWQgbWFudWFsVXBkYXRlKGludCBMLCBpbnQgUiwgaW50IG92YWwsIGludCBudmFsKSB7IC8vIEwgUiBsw6AgxJHhuqd1IHRyw6FpI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AgZm9yIChpbnQgaSA9IDA7IGkgPCBuYmxvY2tzOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSAxMDA7IGorKykgewogICAgICAgICAgICBsYXp5W2ldW2pdID0gajsKICAgICAgICB9CiAgICB9Cn0KCnNpZ25lZCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUobnVsbHB0cik7CiAgICBjaW4gPj4gbjsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY2luID4+IGFbaV07CiAgICB9CiAgICBpbml0KCk7CiAgICBpbnQgcTsgY2luID4+IHE7CiAgICBmb3IgKGludCBRID0gMDsgUSA8IHE7IFErKykgewogICAgICAgIGludCBsLCByLCBvdmFsLCBudmFsOwogICAgICAgIGNpbiA+PiBsID4+IHIgPj4gb3ZhbCA+PiBudmFsOwogICAgICAgIGwtLTsgci0tOwogICAgICAgIHVwZGF0ZShsLCByLCBvdmFsLCBudmFsKTsKICAgIH0KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbmJsb2NrczsgaSsrKSB7CiAgICAgICAgZG9MYXp5KGkpOwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBjb3V0IDw8IGFbaV0gPDwgc3A7CiAgICB9CiAgICBjb3V0IDw8IGVuZGw7Cn0=