#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

char node[101][800000], arr[200002];

void push(int v)
{
    fol(i,1,101)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,101) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, int x, int y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,101) if(node[v][i]==x) node[v][i]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,800000) fol(i,0,101) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int x, y;
        cin>>u>>v>>x>>y;
        upd(1,u,v,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
         cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

char node[MARR][525000], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, char x, char y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[i][v]==x) node[i][v]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,525000) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int l, r, x, y;
        cin>>l>>r>>x>>y;
        upd(1,l,r,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

unsigned char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        short x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%d ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhd", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        char x, y;
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
}


# include <iostream>
# include <stdio.h>
using namespace std;

unsigned char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        short x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%d ", a[i]);
    }
}


# include <iostream>
# include <stdio.h>
using namespace std;

unsigned char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        unsigned char x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhu ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

unsigned char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        unsigned char x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhu ", a[i]);
    }
}


# include <iostream>
# include <stdio.h>
using namespace std;

char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhd", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        char x, y;
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
# include <iostream>
# include <stdio.h>
using namespace std;

char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhd", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        char x, y;
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

unsigned char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        short x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhu ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

short int a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hd", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        unsigned short int x, y;
        scanf("%d%d%hd%hd", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hd ", a[i]);
    }
}


#pragma GCC optimize ("unroll-loops")
# include <iostream>
# include <stdio.h>
using namespace std;

char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhd", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        char x, y;
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

unsigned short int a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        unsigned short int x, y;
        scanf("%d%d%hu%hu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hu ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

unsigned char a[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        unsigned char x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhu ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

int a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        int x, y;
        scanf("%d%d%d%d", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%d ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
# include <iostream>
# include <stdio.h>
using namespace std;

char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhd", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        char x, y;
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

char a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        char x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhu ", a[i]);
    }
}


# include <iostream>
# include <stdio.h>
using namespace std;

unsigned char a[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hhu", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        unsigned char x, y;
        scanf("%d%d%hhu%hhu", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhu ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

unsigned short int a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%u", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        unsigned short int x, y;
        scanf("%d%d%u%u", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%u ", a[i]);
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <iostream>
# include <stdio.h>
using namespace std;

short int a[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%hd", &a[i]);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int l, r;
        short x, y;
        scanf("%d%d%hd%hd", &l, &r, &x, &y);
        for (int i = l-1; i < r; i++) {
            a[i] = a[i] == x ? y : a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%d ", a[i]);
    }
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

typedef long long lli;

const int N = 2e5 + 5;

int seg[4*N][100];

// sum update
void update(int l, int r, int x, int y, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) return;
	if (ll >= l && rl <= r) {
		seg[root][x] = y;
		return;
	}
	update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
	update(l, r, x, y, (ll+rl)/2+1, rl, 2*root+2);
	for (int i=0;i<100;i++) {
		seg[root][i] = seg[2*root+2][seg[2*root+1][i]];
	}
}

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	scanf("%d", &q);
	for (int i=0;i<4*q;i++) {
		for (int j=0;j<100;j++)
			seg[i][j] = j;
	}
	vector<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.pb(mp(mp(l, 0), mp(x, mp(y, j))));
		s.pb(mp(mp(r, 1), mp(x, mp(x, j))));
	}
	s.pb(mp(mp(n, 0), mp(0, mp(0, 0))));
	sort(s.begin(), s.end());
	int cur = 0;
	for (auto b : s) {
		if (b.first.second == 1) for (;cur <= b.first.first; cur++) {
			printf("%d ", seg[0][a[cur]]+1);
		}
		if (b.first.second == 0) for (;cur < b.first.first; cur++) {
			printf("%d ", seg[0][a[cur]]+1);
		}
		debug("chaging query %d from %d to %d\n", b.second.second.second, b.second.first, b.second.second.first);
		update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair

typedef long long lli;

const int N = 2e5 + 5;

struct seg_tree {
	int seg[4*N][100];

	// sum update
	int update(int l, int r, int x, int y, int ll = 0, int rl = N-1, int root = 0) {
		if (r < ll || l > rl) return seg[root][x];
		if (ll >= l && rl <= r) {
			return seg[root][x] = y;
		}
		int update_left = update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
		int update_right = update(l, r, update_left, y, (ll+rl)/2+1, rl, 2*root+2);
		return seg[root][x] = update_right;
	}

	int query(int l, int r, int a, int ll = 0, int rl = N-1, int root = 0) {
		if (r < ll || l > rl) {
			return a;
		}
		if (ll >= l && rl <= r) return seg[root][a];
		int query_left = query(l, r, a, ll, (ll+rl)/2, 2*root+1);
		int query_right = query(l, r, query_left, (ll+rl)/2+1, rl, 2*root+2);
		return query_right;
	}
};

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	seg_tree sg;
	scanf("%d", &q);
	for (int i=0;i<q;i++) {
		for (int j=0;j<100;j++)
			sg.update(i, i, j, j, 0, q-1, 0);
	}
	set<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.insert(mp(mp(l, 0), mp(x, mp(y, j))));
		s.insert(mp(mp(r, 1), mp(x, mp(y, j))));
	}
	s.insert(mp(mp(n, 0), mp(0, mp(0, 0))));
	int cur = 0;
	for (auto b : s) {
		for (;cur < b.first.first; cur++) {
			//sg.print(5); getchar();
			printf("%lld ", sg.query(0, q-1, a[cur], 0, q-1, 0)+1);
		}
		sg.update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair

typedef long long lli;

const int N = 2e5 + 5;

struct seg_tree {
	lli seg[4*N][100];

	// sum update
	lli update(lli l, lli r, lli x, lli y, lli ll = 0, lli rl = N-1, lli root = 0) {
		if (r < ll || l > rl) return seg[root][x];
		if (ll >= l && rl <= r) {
			return seg[root][x] = y;
		}
		lli update_left = update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
		lli update_right = update(l, r, update_left, y, (ll+rl)/2+1, rl, 2*root+2);
		//printf("l = %lld, r = %lld, x = %lld, y = %lld, ll = %lld, rl = %lld, root = %lld, update_left = %lld, update_right = %lld\n", l, r, x, y, ll, rl, root, update_left, update_right);
		return seg[root][x] = update_right;
	}

	lli query(lli l, lli r, lli a, lli ll = 0, lli rl = N-1, int root = 0) {
		if (r < ll || l > rl) {
			return a;
		}
		if (ll >= l && rl <= r) return seg[root][a];
		lli query_left = query(l, r, a, ll, (ll+rl)/2, 2*root+1);
		lli query_right = query(l, r, query_left, (ll+rl)/2+1, rl, 2*root+2);
		return query_right;
	}
	void print(int a) {
		for (int j=0;j<a;j++) {
			printf("seg[0][%d] = %lld\n", j, seg[0][j]);
		}
	}
};

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	seg_tree sg;
	scanf("%d", &q);
	for (int i=0;i<q;i++) {
		for (int j=0;j<100;j++)
			sg.update(i, i, j, j, 0, q-1, 0);
	}
	set<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.insert(mp(mp(l, 0), mp(x, mp(y, j))));
		s.insert(mp(mp(r, 1), mp(x, mp(y, j))));
	}
	s.insert(mp(mp(n, 0), mp(0, mp(0, 0))));
	int cur = 0;
	for (auto b : s) {
		for (;cur < b.first.first; cur++) {
			//sg.print(5); getchar();
			printf("%lld ", sg.query(0, q-1, a[cur], 0, q-1, 0)+1);
		}
		sg.update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

typedef long long lli;

const int N = 2e5 + 5;

int seg[4*N][100];

// sum update
void update(int l, int r, int x, int y, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) return;
	if (ll >= l && rl <= r) {
		seg[root][x] = y;
		return;
	}
	update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
	update(l, r, x, y, (ll+rl)/2+1, rl, 2*root+2);
	for (int i=0;i<100;i++) {
		seg[root][i] = seg[2*root+2][seg[2*root+1][i]];
	}
}

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	scanf("%d", &q);
	for (int i=0;i<4*q;i++) {
		for (int j=0;j<100;j++)
			seg[i][j] = j;
	}
	vector<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.pb(mp(mp(l, 0), mp(x, mp(y, j))));
		s.pb(mp(mp(r, 1), mp(x, mp(x, j))));
	}
	s.pb(mp(mp(n, 0), mp(0, mp(0, 0))));
	sort(s.begin(), s.end());
	int cur = 0;
	for (auto b : s) {
		if (b.first.second == 1) for (;cur <= b.first.first; cur++) {
			printf("%d ", seg[0][a[cur]]+1);
		}
		//printf("chaging query %d from %d to %d\n", b.second.second.second, b.second.first, b.second.second.first);
		update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

typedef long long lli;

const int N = 2e5 + 5;

int seg[4*N][100];

// sum update
int update(int l, int r, int x, int y, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) return seg[root][x];
	if (ll >= l && rl <= r) {
		return seg[root][x] = y;
	}
	int update_left = update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
	int update_right = update(l, r, update_left, y, (ll+rl)/2+1, rl, 2*root+2);
	return seg[root][x] = update_right;
}

int query(int l, int r, int a, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) {
		return a;
	}
	if (ll >= l && rl <= r) return seg[root][a];
	int query_left = query(l, r, a, ll, (ll+rl)/2, 2*root+1);
	int query_right = query(l, r, query_left, (ll+rl)/2+1, rl, 2*root+2);
	return query_right;
}

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	scanf("%d", &q);
	for (int i=0;i<4*q;i++) {
		for (int j=0;j<100;j++)
			seg[i][j] = j;
	}
	vector<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.pb(mp(mp(l, 0), mp(x, mp(y, j))));
		s.pb(mp(mp(r, 1), mp(x, mp(y, j))));
	}
	s.pb(mp(mp(n, 0), mp(0, mp(0, 0))));
	sort(s.begin(), s.end());
	int cur = 0;
	for (auto b : s) {
		for (;cur < b.first.first; cur++) {
			//sg.print(5); getchar();
			printf("%d ", query(0, q-1, a[cur], 0, q-1, 0)+1);
		}
		update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

typedef long long lli;

const int N = 2e5 + 5;

int seg[4*N][100];

// sum update
void update(int l, int r, int x, int y, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) return;
	if (ll >= l && rl <= r) {
		seg[root][x] = y;
		return;
	}
	update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
	update(l, r, x, y, (ll+rl)/2+1, rl, 2*root+2);
	for (int i=0;i<100;i++) {
		seg[root][i] = seg[2*root+2][seg[2*root+1][i]];
	}
}

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	scanf("%d", &q);
	for (int i=0;i<4*q;i++) {
		for (int j=0;j<100;j++)
			seg[i][j] = j;
	}
	vector<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.pb(mp(mp(l, 0), mp(x, mp(y, j))));
		s.pb(mp(mp(r, 1), mp(x, mp(x, j))));
	}
	s.pb(mp(mp(n, 0), mp(0, mp(0, 0))));
	sort(s.begin(), s.end());
	int cur = 0;
	for (auto b : s) {
		if (b.first.second == 1) for (;cur <= b.first.first; cur++) {
			printf("%d ", seg[0][a[cur]]+1);
		}
		if (b.first.second == 0) for (;cur < b.first.first; cur++) {
			printf("%d ", seg[0][a[cur]]+1);
		}
		//printf("chaging query %d from %d to %d\n", b.second.second.second, b.second.first, b.second.second.first);
		update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair

typedef long long lli;

const int N = 2e5 + 5;

int seg[4*N][100];

// sum update
int update(int l, int r, int x, int y, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) return seg[root][x];
	if (ll >= l && rl <= r) {
		return seg[root][x] = y;
	}
	int update_left = update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
	int update_right = update(l, r, update_left, y, (ll+rl)/2+1, rl, 2*root+2);
	return seg[root][x] = update_right;
}

int query(int l, int r, int a, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) {
		return a;
	}
	if (ll >= l && rl <= r) return seg[root][a];
	int query_left = query(l, r, a, ll, (ll+rl)/2, 2*root+1);
	int query_right = query(l, r, query_left, (ll+rl)/2+1, rl, 2*root+2);
	return query_right;
}

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	scanf("%d", &q);
	for (int i=0;i<q;i++) {
		for (int j=0;j<100;j++)
			update(i, i, j, j, 0, q-1, 0);
	}
	set<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.insert(mp(mp(l, 0), mp(x, mp(y, j))));
		s.insert(mp(mp(r, 1), mp(x, mp(y, j))));
	}
	s.insert(mp(mp(n, 0), mp(0, mp(0, 0))));
	int cur = 0;
	for (auto b : s) {
		for (;cur < b.first.first; cur++) {
			//sg.print(5); getchar();
			printf("%d ", query(0, q-1, a[cur], 0, q-1, 0)+1);
		}
		update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

typedef long long lli;

const int N = 2e5 + 5;

int seg[4*N][100];

// sum update
int update(int l, int r, int x, int y, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) return seg[root][x];
	if (ll >= l && rl <= r) {
		return seg[root][x] = y;
	}
	int update_left = update(l, r, x, y, ll, (ll+rl)/2, 2*root+1);
	int update_right = update(l, r, update_left, y, (ll+rl)/2+1, rl, 2*root+2);
	return seg[root][x] = update_right;
}

int query(int l, int r, int a, int ll = 0, int rl = N-1, int root = 0) {
	if (r < ll || l > rl) {
		return a;
	}
	if (ll >= l && rl <= r) return seg[root][a];
	int query_left = query(l, r, a, ll, (ll+rl)/2, 2*root+1);
	int query_right = query(l, r, query_left, (ll+rl)/2+1, rl, 2*root+2);
	return query_right;
}

int a[N];
int main() {
	int n, q;
	scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	scanf("%d", &q);
	for (int i=0;i<q;i++) {
		for (int j=0;j<100;j++)
			update(i, i, j, j, 0, q-1, 0);
	}
	vector<pair<pair<int, int>, pair<int, pair<int, int> > > > s;
	for (int j=0;j<q;j++) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		l--; r--; x--; y--;
		s.pb(mp(mp(l, 0), mp(x, mp(y, j))));
		s.pb(mp(mp(r, 1), mp(x, mp(y, j))));
	}
	s.pb(mp(mp(n, 0), mp(0, mp(0, 0))));
	sort(s.begin(), s.end());
	int cur = 0;
	for (auto b : s) {
		for (;cur < b.first.first; cur++) {
			//sg.print(5); getchar();
			printf("%d ", query(0, q-1, a[cur], 0, q-1, 0)+1);
		}
		update(b.second.second.second, b.second.second.second, b.second.first, b.second.second.first, 0, q-1, 0);
	} printf("\n");
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
uint8_t a[N],x,y;int l,r,q,n;
main(){
	scanf("%d",&n);
	for(int i =0; i < n; ++i){
		scanf("%hhu",&a[i]);
	}
	scanf("%d",&q);
	while(q--){
		scanf("%d%d%hhu%hhu",&l,&r,&x,&y);
		--l;
		for(int i=l;i<r;++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		printf("%hhu ", a[i]);
	}
	printf("\n");
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
char a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
uint8_t a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
//	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4,avx")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
unsigned char a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4,avx")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
char a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int8_t a[N];int x,y,l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		int b;
		cin >> b;
		a[i] = b;
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		int8_t h = x, g = y;
		for(int i = l; i <= r; ++i){
			if(a[i] == h)a[i] = g;
		}
	}
	for(int i = 0; i < n; ++i){
		int b = a[i];
		cout << b << ' ';
	}
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC targe("sse4")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
char a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
uint8_t a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
char a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int a[N],x,y;int l,r,q,n;
main(){
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	cin >> n;
	for(int i =0; i < n; ++i){
		cin >> a[i];
	}
	cin >> q;
	while(q--){
		cin >> l >> r >> x >> y;--l;--r;
		for(int i = l; i <= r; ++i){
			if(a[i] == x)a[i] = y;
		}
	}
	for(int i = 0; i < n; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
const int NN=272727;
const int MM=101;

int d[NN][MM],s[2][MM];
int fl[NN][MM],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

void push_up(int u){
	for(int i=1;i<MM;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=1;i<MM;i++) fl[u][i]=i;
	if(l+1==r){
		d[u][a[l]]=1;
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	for(int i=1;i<MM;i++) s[0][i]=s[1][i]=0;

	for(int i=1;i<MM;i++){
		if(fl[u][i]!=i) s[0][fl[u][i]]+=d[ls][i],d[ls][i]=0;
		else s[0][i]+=d[ls][i];
	}
	for(int i=1;i<MM;i++) d[ls][i]=s[0][i];

	for(int i=1;i<MM;i++){
		if(fl[u][i]!=i) s[1][fl[u][i]]+=d[rs][i],d[rs][i]=0;
		else s[1][i]+=d[rs][i];
	}
	for(int i=1;i<MM;i++) d[rs][i]=s[1][i];

	for(int i=1;i<MM;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=1;i<MM;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=1;i<MM;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
		for(int i=1;i<MM;i++) if(fl[u][i]==x) fl[u][i]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
void print(int u,int l,int r){
	if(l+1==r){
		int A=0;
		for(int i=1;i<MM;i++) if(d[u][i]) {A=i;break;}
		printf("%d ",A);
		return ;
	}
	push_down(u);
	print(ls,l,mid);
	print(rs,mid,r);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif

	int n,q;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);

	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int st,ed,x,y;
		scanf("%d%d%d%d",&st,&ed,&x,&y);
		if(x!=y) change(1,1,n+1,st,ed+1,x,y);
	}
	print(1,1,n+1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using INT=long long;
const int NN=272727;
int d[NN][101];
int fl[NN][101],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
void push_up(int u){
	for(int i=1;i<101;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=1;i<101;i++) fl[u][i]=i;
	if(l+1==r){
		d[u][a[l]]++;
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	int s[2][101];
	for(int i=1;i<101;i++) s[0][i]=s[1][i]=0;

	for(int i=1;i<101;i++){
		if(fl[u][i]!=i) s[0][fl[u][i]]+=d[ls][i],d[ls][i]=0;
		else s[0][i]+=d[ls][i];
	}
	for(int i=1;i<101;i++) d[ls][i]=s[0][i];

	for(int i=1;i<101;i++){
		if(fl[u][i]!=i) s[1][fl[u][i]]+=d[rs][i],d[rs][i]=0;
		else s[1][i]+=d[rs][i];
	}
	for(int i=1;i<101;i++) d[rs][i]=s[1][i];

	for(int i=1;i<101;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=1;i<101;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=1;i<101;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
		for(int i=1;i<101;i++) if(fl[u][i]==x) fl[u][i]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
void print(int u,int l,int r){
	if(l+1==r){
		int A=0;
		for(int i=1;i<101;i++) if(d[u][i]) {A=i;break;}
		printf("%d ",A);
		return ;
	}
	push_down(u);
	print(ls,l,mid);
	print(rs,mid,r);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif

	int n,q;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);

	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int st,ed,x,y;
		scanf("%d%d%d%d",&st,&ed,&x,&y);
		if(x!=y) change(1,1,n+1,st,ed+1,x,y);
	}
	print(1,1,n+1);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int NN=272727;
const int MM=101;

int d[NN][MM];
int fl[NN][MM],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

void push_up(int u){
	for(int i=1;i<MM;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=1;i<MM;i++) fl[u][i]=i;
	if(l+1==r){
		d[u][a[l]]=1;
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	int s[2][MM];
	for(int i=1;i<MM;i++) s[0][i]=s[1][i]=0;

	for(int i=1;i<MM;i++){
		if(fl[u][i]!=i) s[0][fl[u][i]]+=d[ls][i],d[ls][i]=0;
		else s[0][i]+=d[ls][i];
	}
	for(int i=1;i<MM;i++) d[ls][i]=s[0][i];

	for(int i=1;i<MM;i++){
		if(fl[u][i]!=i) s[1][fl[u][i]]+=d[rs][i],d[rs][i]=0;
		else s[1][i]+=d[rs][i];
	}
	for(int i=1;i<MM;i++) d[rs][i]=s[1][i];

	for(int i=1;i<MM;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=1;i<MM;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=1;i<MM;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
		for(int i=1;i<MM;i++) if(fl[u][i]==x) fl[u][i]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
void print(int u,int l,int r){
	if(l+1==r){
		int A=0;
		for(int i=1;i<101;i++) if(d[u][i]) {A=i;break;}
		printf("%d ",A);
		return ;
	}
	push_down(u);
	print(ls,l,mid);
	print(rs,mid,r);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif

	int n,q;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);

	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int st,ed,x,y;
		scanf("%d%d%d%d",&st,&ed,&x,&y);
		if(x!=y) change(1,1,n+1,st,ed+1,x,y);
	}
	print(1,1,n+1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int NN=572727;
const int MM=101;

int d[NN][MM],s[2][MM];
int fl[NN][MM],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

void push_up(int u){
	for(int i=1;i<MM;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=1;i<MM;i++) fl[u][i]=i;
	if(l+1==r){
		d[u][a[l]]=1;
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	for(int i=1;i<MM;i++) s[0][i]=s[1][i]=0;

	for(int i=1;i<MM;i++){
		if(fl[u][i]!=i) s[0][fl[u][i]]+=d[ls][i],d[ls][i]=0;
		else s[0][i]+=d[ls][i];
	}
	for(int i=1;i<MM;i++) d[ls][i]=s[0][i];

	for(int i=1;i<MM;i++){
		if(fl[u][i]!=i) s[1][fl[u][i]]+=d[rs][i],d[rs][i]=0;
		else s[1][i]+=d[rs][i];
	}
	for(int i=1;i<MM;i++) d[rs][i]=s[1][i];

	for(int i=1;i<MM;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=1;i<MM;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=1;i<MM;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
		for(int i=1;i<MM;i++) if(fl[u][i]==x) fl[u][i]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
void print(int u,int l,int r){
	if(l+1==r){
		int A=0;
		for(int i=1;i<MM;i++) if(d[u][i]) {A=i;break;}
		printf("%d ",A);
		return ;
	}
	push_down(u);
	print(ls,l,mid);
	print(rs,mid,r);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif

	int n,q;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);

	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int st,ed,x,y;
		scanf("%d%d%d%d",&st,&ed,&x,&y);
		if(x!=y) change(1,1,n+1,st,ed+1,x,y);
	}
	print(1,1,n+1);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define NN 100010
#define MM 111

#define ls (u << 1)
#define rs (ls | 1)
#define mid (L + R >> 1)

using INT = long long;

int flag[NN*4][MM];
int n, q;
int a[NN];

int build(int u, int L, int R) {
	for(int i=0; i<MM; i++) flag[u][i] = i;
	if(L + 1 == R) return 0;
	build(ls, L, mid);
	build(rs, mid, R);
}

inline int push_down(int u) {
	for(int i=0; i<MM; i++) {
		flag[ls][i] = flag[u][flag[ls][i]];
		flag[rs][i] = flag[u][flag[rs][i]];
	}
	for(int i=0; i<MM; i++) {
		flag[u][i] = i;
	}
	return 0;
}

int update(int u, int L, int R, int st, int ed, int x, int y) {
	if(L >= ed || R <= st) return 0;

	if(L >= st and R <= ed) {
		for(int i=0; i<MM; i++) {
			if(flag[u][i] == x) flag[u][i] = y;
		}
		return 0;
	}
	push_down(u);
	update(ls, L, mid, st, ed, x, y);
	update(rs, mid, R, st, ed, x, y);
}

inline INT calc(int u, int L, int R) {
	if(L + 1 == R) {
		printf("%d ", flag[u][a[L]]);
		return 0;
	}
	push_down(u);
	calc(ls, L, mid);
	calc(rs, mid, R);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin >> n;

	for(int i=1; i<=n; i++) {
		scanf("%d", &a[i]);
	}
	int Q; cin >> Q;
	build(1, 1, n + 1);

	while(Q--) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		update(1, 1, n + 1, l, r + 1, x, y);
	}

	calc(1, 1, n + 1);
}


#include<bits/stdc++.h>

using namespace std;

#define NN 200010
#define MM 101

#define ls (u << 1)
#define rs (ls | 1)
#define mid (L + R >> 1)

using INT = long long;

int flag[NN*4][MM];
int n, q;
int a[NN];

int build(int u, int L, int R) {
	for(int i=0; i<MM; i++) flag[u][i] = i;
	if(L + 1 == R) return 0;
	build(ls, L, mid);
	build(rs, mid, R);
}

inline int push_down(int u) {
	for(int i=0; i<MM; i++) {
		flag[ls][i] = flag[u][flag[ls][i]];
		flag[rs][i] = flag[u][flag[rs][i]];
	}
	for(int i=0; i<MM; i++) {
		flag[u][i] = i;
	}
	return 0;
}

int update(int u, int L, int R, int st, int ed, int x, int y) {
	if(L >= ed || R <= st) return 0;

	if(L >= st and R <= ed) {
		for(int i=0; i<MM; i++) {
			if(flag[u][i] == x) flag[u][i] = y;
		}
		return 0;
	}
	push_down(u);
	update(ls, L, mid, st, ed, x, y);
	update(rs, mid, R, st, ed, x, y);
}

inline INT calc(int u, int L, int R) {
	if(L + 1 == R) {
		printf("%d ", flag[u][a[L]]);
		return 0;
	}
	push_down(u);
	calc(ls, L, mid);
	calc(rs, mid, R);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin >> n;

	for(int i=1; i<=n; i++) {
		scanf("%d", &a[i]);
	}
	int Q; cin >> Q;
	build(1, 1, n + 1);

	while(Q--) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		update(1, 1, n + 1, l, r + 1, x, y);
	}

	calc(1, 1, n + 1);
}


#include<bits/stdc++.h>
using namespace std;
const int NN=572727;
const int MM=101;

int fl[NN][MM],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

void build(int u,int l,int r){
	for(int i=1;i<MM;i++) fl[u][i]=i;
	if(l+1==r) return;
	build(ls,l,mid);
	build(rs,mid,r);
}
void push_down(int u){
	for(int i=1;i<MM;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=1;i<MM;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}
	for(int i=1;i<MM;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		for(int i=1;i<MM;i++) if(fl[u][i]==x) fl[u][i]=y;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
}
void print(int u,int l,int r){
	if(l+1==r){
		printf("%d ",fl[u][a[l]]);
		return ;
	}
	push_down(u);
	print(ls,l,mid);
	print(rs,mid,r);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif

	int n,q;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);

	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int st,ed,x,y;
		scanf("%d%d%d%d",&st,&ed,&x,&y);
		if(x!=y) change(1,1,n+1,st,ed+1,x,y);
	}
	print(1,1,n+1);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define NN 200010
#define MM 101

#define ls (u << 1)
#define rs (ls | 1)
#define mid (L + R >> 1)

using INT = long long;

int flag[NN*4][MM];
int n, q;
int a[NN];

int build(int u, int L, int R) {
	for(int i=0; i<MM; i++) flag[u][i] = i;
	if(L + 1 == R) return 0;
	build(ls, L, mid);
	build(rs, mid, R);
}

inline int push_down(int u) {
	for(int i=0; i<MM; i++) {
		flag[ls][i] = flag[u][flag[ls][i]];
		flag[rs][i] = flag[u][flag[rs][i]];
	}

//	for(int i=0; i<MM; i++) {
//		flag[u][i] = i;
//	}
	return 0;
}

int update(int u, int L, int R, int st, int ed, int x, int y) {
	if(L >= ed || R <= st) return 0;

	if(L >= st and R <= ed) {
		for(int i=0; i<MM; i++) {
			if(flag[u][i] == x) flag[u][i] = y;
		}
		return 0;
	}
	push_down(u);
	update(ls, L, mid, st, ed, x, y);
	update(rs, mid, R, st, ed, x, y);
}

inline INT calc(int u, int L, int R) {
	if(L + 1 == R) {
		printf("%d ", flag[u][a[L]]);
		return 0;
	}
	push_down(u);
	calc(ls, L, mid);
	calc(rs, mid, R);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin >> n;

	for(int i=1; i<=n; i++) {
		scanf("%d", &a[i]);
	}
	int Q; cin >> Q;
	build(1, 1, n + 1);

	while(Q--) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		update(1, 1, n + 1, l, r + 1, x, y);
	}

	calc(1, 1, n + 1);
}


#include<bits/stdc++.h>
using namespace std;
const int NN=272727;
int d[NN][110],fl[NN][110],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
void push_up(int u){
	for(int i=1;i<101;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=1;i<101;i++) fl[u][i]=i;
	if(l+1==r){
		d[u][a[l]]++;
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	int s[2][110];
	for(int i=1;i<101;i++) s[0][i]=s[1][i]=0;

	for(int i=1;i<101;i++){
		if(fl[u][i]!=i) s[0][fl[u][i]]+=d[ls][i],d[ls][i]=0;
		else s[0][i]+=d[ls][i];
	}
	for(int i=1;i<101;i++) d[ls][i]=s[0][i];

	for(int i=1;i<101;i++){
		if(fl[u][i]!=i) s[1][fl[u][i]]+=d[rs][i],d[rs][i]=0;
		else s[1][i]+=d[rs][i];
	}
	for(int i=1;i<101;i++) d[rs][i]=s[1][i];

	for(int i=1;i<101;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=1;i<101;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=1;i<101;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
		for(int i=1;i<101;i++) if(fl[u][i]==x) fl[u][i]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
void print(int u,int l,int r){
	if(l+1==r){
		int A=0;
		for(int i=1;i<101;i++) if(d[u][i]) {A=i;break;}
		printf("%d ",A);
		return ;
	}
	push_down(u);
	print(ls,l,mid);
	print(rs,mid,r);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif

	int n,q;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);

	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int st,ed,x,y;
		scanf("%d%d%d%d",&st,&ed,&x,&y);
		if(x!=y) change(1,1,n+1,st,ed+1,x,y);
	}
	print(1,1,n+1);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 	200010
int flag[NN<<2][111];
int a[NN];
int n, m;

#define ls (u << 1)
#define rs (ls | 1)
#define mid (l + r >> 1)

void push_down(int u) {
	for(int i=1; i<=100; i++) {
		flag[ls][i] = flag[u][flag[ls][i]];
		flag[rs][i] = flag[u][flag[rs][i]];
	}
	for(int i=1; i<=100; i++) flag[u][i] = i;
}

void build(int u, int l, int r) {
	for(int i=1; i<=100; i++) flag[u][i] = i;
	if(l + 1 == r) return;
	build(ls, l, mid);
	build(rs, mid, r);
}

void update(int u, int l, int r,int st, int ed, int x, int y) {
	if(l >= ed or r <= st) return;
	if(l >= st and r <= ed) {
		for(int i=1; i<=100; i++) if(flag[u][i] == x) flag[u][i] = y;
		return;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
}

void calc(int u, int l, int r) {
	if (l + 1 == r) {
		cout << flag[u][a[l]] << " ";
		return;
	}
	push_down(u);
	calc(ls, l, mid);
	calc(rs, mid, r);
}

int main () {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    freopen("out.out","w",stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=1; i<=n; i++) cin >> a[i];
	build(1, 1, n+1);
	cin >> m;
	for(int i=1; i<=m; i++) {
		int l, r, x, y;
		cin >> l >> r >> x >> y;
		update(1, 1, n +1, l, r + 1, x, y);
	}
	calc(1, 1, n+1);
    return 0;
}


#include<bits/stdc++.h>
#define NN 200100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
#define MM 110

using namespace std;

int flag[NN<<2][MM], a[NN];

void build(int u, int l, int r) {
	for(int i=0; i<MM; i++) flag[u][i]=i;
	if(l+1==r) return ;
	build(ls, l, mid);
	build(rs, mid, r);
}

void push_down(int u) {
	for(int i=0; i<MM; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		flag[rs][i]=flag[u][flag[rs][i]];
	}
	for(int i=0; i<MM; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		for(int i=0; i<MM; i++) if(flag[u][i]==x) flag[u][i]=y;
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
}

void calc(int u, int l, int r) {
	if(l+1==r) {
		printf("%d ", flag[u][a[l]]);
		return ;
	}
	push_down(u);
	calc(ls, l, mid);
	calc(rs, mid, r);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);
	int q;
	cin>>q;
	while(q--) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		update(1, 1, n+1, l, r+1, x, y);
	}
	calc(1, 1, n+1);

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define NN 200010
#define MM 111

#define ls (u << 1)
#define rs (ls | 1)
#define mid (L + R >> 1)

using INT = long long;

int flag[NN*4][MM];
int n, q;
int a[NN];

int build(int u, int L, int R) {
	for(int i=0; i<MM; i++) flag[u][i] = i;
	if(L + 1 == R) return 0;
	build(ls, L, mid);
	build(rs, mid, R);
}

inline int push_down(int u) {
	for(int i=0; i<MM; i++) {
		flag[ls][i] = flag[u][flag[ls][i]];
		flag[rs][i] = flag[u][flag[rs][i]];
	}
	for(int i=0; i<MM; i++) {
		flag[u][i] = i;
	}
	return 0;
}

int update(int u, int L, int R, int st, int ed, int x, int y) {
	if(L >= ed || R <= st) return 0;

	if(L >= st and R <= ed) {
		for(int i=0; i<MM; i++) {
			if(flag[u][i] == x) flag[u][i] = y;
		}
		return 0;
	}
	push_down(u);
	update(ls, L, mid, st, ed, x, y);
	update(rs, mid, R, st, ed, x, y);
}

inline INT calc(int u, int L, int R) {
	if(L + 1 == R) {
		printf("%d ", flag[u][a[L]]);
		return 0;
	}
	push_down(u);
	calc(ls, L, mid);
	calc(rs, mid, R);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin >> n;

	for(int i=1; i<=n; i++) {
		scanf("%d", &a[i]);
	}
	int Q; cin >> Q;
	build(1, 1, n + 1);

	while(Q--) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		update(1, 1, n + 1, l, r + 1, x, y);
	}

	calc(1, 1, n + 1);
}


#include<bits/stdc++.h>
#define NN 200100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
#define MM 100

using namespace std;

int flag[NN<<2][110], a[NN];

void build(int u, int l, int r) {
	for(int i=1; i<=MM; i++) flag[u][i]=i;
	if(l+1==r) return ;
	build(ls, l, mid);
	build(rs, mid, r);
}

void push_down(int u) {
	for(int i=1; i<=MM; i++) {
		if(flag[u][i]==i) continue;
		flag[ls][i]=flag[u][i];
		flag[rs][i]=flag[u][i];
		flag[u][i]=i;
	}
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		for(int i=1; i<=MM; i++) if(flag[u][i]==x) flag[u][i]=y;
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
}

void calc(int u, int l, int r) {
	if(l+1==r) {
		printf("%d ", flag[u][a[l]]);
		return ;
	}
	push_down(u);
	calc(ls, l, mid);
	calc(rs, mid, r);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);
	int q;
	cin>>q;
	while(q--) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		update(1, 1, n+1, l, r+1, x, y);
	}
	calc(1, 1, n+1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int NN=532727;
const int MM=101;
int fl[NN][MM],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
void build(int u,int l,int r){
	for(int i=1;i<MM;i++) fl[u][i]=i;
	if(l+1==r) return;
	build(ls,l,mid);
	build(rs,mid,r);
}
void push_down(int u){
	for(int i=1;i<MM;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
		fl[rs][i]=fl[u][fl[rs][i]];
	}
	for(int i=1;i<MM;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		for(int i=1;i<MM;i++) if(fl[u][i]==x) fl[u][i]=y;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
}
void print(int u,int l,int r){
	if(l+1==r){
		printf("%d ",fl[u][a[l]]);
		return ;
	}
	push_down(u);
	print(ls,l,mid);
	print(rs,mid,r);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,q;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int st,ed,x,y;
		scanf("%d%d%d%d",&st,&ed,&x,&y);
		if(x!=y) change(1,1,n+1,st,ed+1,x,y);
	}
	print(1,1,n+1);
	return 0;
}


#include<bits/stdc++.h>
#define NN 200100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
#define MM 100

using namespace std;

int flag[NN<<2][110], a[NN];

void build(int u, int l, int r) {
	for(int i=1; i<=MM; i++) flag[u][i]=i;
	if(l+1==r) return ;
	build(ls, l, mid);
	build(rs, mid, r);
}

void push_down(int u) {
	for(int i=1; i<=MM; i++) {
		if(flag[u][i]==i) continue;
		flag[ls][i]=flag[u][flag[ls][i]];
		flag[rs][i]=flag[u][flag[rs][i]];
	}
	for(int i=1; i<=MM; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		for(int i=1; i<=MM; i++) if(flag[u][i]==x) flag[u][i]=y;
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
}

void calc(int u, int l, int r) {
	if(l+1==r) {
		printf("%d ", flag[u][a[l]]);
		return ;
	}
	push_down(u);
	calc(ls, l, mid);
	calc(rs, mid, r);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);
	int q;
	cin>>q;
	while(q--) {
		int l, r, x, y;
		scanf("%d %d %d %d", &l, &r, &x, &y);
		update(1, 1, n+1, l, r+1, x, y);
	}
	calc(1, 1, n+1);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int NN = 565656;
const int MM = 111;

int a[NN];
int flag[NN][MM];

#define ls (u<<1)
#define rs (ls|1)
#define mid (L+R>>1)

void push_down(int u) {
	for(int i=0; i<MM; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		flag[rs][i]=flag[u][flag[rs][i]];
	}
	for(int i=0; i<MM; i++) {
		flag[u][i] = i;
	}
}

void update(int u, int L, int R, int st, int ed, int x, int y) {
	if(L >= ed || R <= st) return ;
	if(L >= st && R <= ed) {
		for(int i=0; i<MM; i++) {
			if(flag[u][i] == x) flag[u][i] = y;
		}
		return ;
	}
	push_down(u);
	update(ls, L, mid, st, ed, x, y);
	update(rs, mid, R, st, ed, x, y);
}

void print(int u, int L, int R) {
	if(L + 1 == R ){
		printf("%d ", flag[u][a[L]]);
		return ;
	}
	push_down(u);
	print(ls, L, mid);
	print(rs, mid, R);
}

void build(int u, int L, int R) {
	for(int i=0; i<MM; i++) flag[u][i] = i;
	if(L+1==R) return ;
	build(ls, L, mid);
	build(rs, mid, R);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n; cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	build(1, 1, n+1);

	int m; cin>>m;
	while(m--) {
		int st, ed, x, y;
		scanf("%d %d %d %d", &st, &ed, &x, &y);
		update(1, 1, n+1, st, ed+1, x, y);
	}
	print(1, 1, n+1);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

int a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        return;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            t[x].p[t[x].val] = 0;
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        if (t[x].p[i]) {
            for (int j = 1; j <= 100; ++j) {
                if (t[l].p[j] == i) {
                    t[l].p[j] = t[x].p[i];
                }
                if (t[r].p[j] == i) {
                    t[r].p[j] = t[x].p[i];
                }
            }
            if (t[l].p[i] == i || t[l].p[i] == 0) {
                t[l].p[i] = t[x].p[i];
            }
            if (t[r].p[i] == i || t[r].p[i] == 0) {
                t[r].p[i] = t[x].p[i];
            }
            t[x].p[i] = 0;
        }
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

int a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        return;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            t[x].p[t[x].val] = 0;
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l].p[i] = t[x].p[ t[l].p[i] ];
        t[r].p[i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = 0;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        for (int i = 1; i <= 100; ++i) {
            t[x].p[i] = i;
        }
        return;
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            for (int i = 1; i <= 100; ++i) {
                t[x].p[i] = i;
            }
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l].p[i] = t[x].p[ t[l].p[i] ];
        t[r].p[i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        for (int i = 1; i <= 100; ++i) {
            t[x].p[i] = i;
        }
        return;
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            for (int i = 1; i <= 100; ++i) {
                t[x].p[i] = i;
            }
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l].p[i] = t[x].p[ t[l].p[i] ];
        t[r].p[i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        //cin >> a[i];
        scanf("%d", a + i);
    }
    build();
    int q;
    //cin >> q;
    scanf("%d", &q);
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        //cin >> l >> r >> x >> y;
        scanf("%d%d%d%d", &l, &r, &x, &y);
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        //cout << find(i) << " ";
        printf("%d ", find(i));
    }
    printf("\n");
    //cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        return;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            memset(t[x].p, 0, sizeof(t[x].p));
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        if (t[x].p[i]) {
            for (int j = 1; j <= 100; ++j) {
                if (t[l].p[j] == i) {
                    t[l].p[j] = t[x].p[i];
                }
                if (t[r].p[j] == i) {
                    t[r].p[j] = t[x].p[i];
                }
            }
            if (t[l].p[i] == i || t[l].p[i] == 0) {
                t[l].p[i] = t[x].p[i];
            }
            if (t[r].p[i] == i || t[r].p[i] == 0) {
                t[r].p[i] = t[x].p[i];
            }
            t[x].p[i] = 0;
        }
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

int a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

unsigned char a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    int q;
    scanf("%d", &q);
    int l, r;
    unsigned char x, y;
    for (int i = 0; i < q; ++i) {
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
    return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        for (int i = 1; i <= 100; ++i) {
            t[x].p[i] = i;
        }
        return;
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            for (int i = 1; i <= 100; ++i) {
                t[x].p[i] = i;
            }
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l].p[i] = t[x].p[ t[l].p[i] ];
        t[r].p[i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        //cin >> a[i];
        scanf("%d", a + i);
    }
    build();
    int q;
    //cin >> q;
    scanf("%d", &q);
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        //cin >> l >> r >> x >> y;
        scanf("%d%d%d%d", &l, &r, &x, &y);
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        //cout << find(i) << " ";
        printf("%d ", find(i));
    }
    printf("\n");
    //cout << endl;
    return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

unsigned char a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    int q;
    scanf("%d", &q);
    int l, r;
    unsigned char x, y;
    for (int i = 0; i < q; ++i) {
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("tune=native")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

unsigned char a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    int q;
    scanf("%d", &q);
    int l, r;
    unsigned char x, y;
    for (int i = 0; i < q; ++i) {
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

unsigned char a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    int l, r;
    unsigned char x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        for (int i = 1; i <= 100; ++i) {
            t[x].p[i] = i;
        }
        return;
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            for (int i = 1; i <= 100; ++i) {
                t[x].p[i] = i;
            }
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l].p[i] = t[x].p[ t[l].p[i] ];
        t[r].p[i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        //cin >> a[i];
        scanf("%d", a + i);
    }
    build();
    int q;
    //cin >> q;
    scanf("%d", &q);
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        //cin >> l >> r >> x >> y;
        scanf("%d%d%d%d", &l, &r, &x, &y);
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        //cout << find(i) << " ";
        printf("%d ", find(i));
    }
    printf("\n");
    //cout << endl;
    return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

unsigned char a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    int q;
    scanf("%d", &q);
    int l, r;
    unsigned char x, y;
    for (int i = 0; i < q; ++i) {
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        for (int i = 1; i <= 100; ++i) {
            t[x].p[i] = i;
        }
        return;
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            for (int i = 1; i <= 100; ++i) {
                t[x].p[i] = i;
            }
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l].p[i] = t[x].p[ t[l].p[i] ];
        t[r].p[i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        for (int i = 1; i <= 100; ++i) {
            t[x].p[i] = i;
        }
        return;
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            for (int i = 1; i <= 100; ++i) {
                t[x].p[i] = i;
            }
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l].p[i] = t[x].p[ t[l].p[i] ];
        t[r].p[i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x].p[i] = i;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

unsigned char a[200000];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    int q;
    scanf("%d", &q);
    int l, r;
    unsigned char x, y;
    for (int i = 0; i < q; ++i) {
        scanf("%d%d%hhd%hhd", &l, &r, &x, &y);
        for (int i = l - 1; i < r; ++i) {
            if (a[i] == x)
                a[i] = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%hhd ", a[i]);
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("tune=native")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        return;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            t[x].p[t[x].val] = 0;
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        if (t[x].p[i]) {
            for (int j = 1; j <= 100; ++j) {
                if (t[l].p[j] == i) {
                    t[l].p[j] = t[x].p[i];
                }
                if (t[r].p[j] == i) {
                    t[r].p[j] = t[x].p[i];
                }
            }
            if (t[l].p[i] == i || t[l].p[i] == 0) {
                t[l].p[i] = t[x].p[i];
            }
            if (t[r].p[i] == i || t[r].p[i] == 0) {
                t[r].p[i] = t[x].p[i];
            }
            t[x].p[i] = 0;
        }
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}