#include<bits/stdc++.h>
using namespace std;
#define scl(n) scanf("%d",&n)
#define ll int
int dsu[302][115000],ara[100005],nxt[302],track[302][10002];
int fnd(ll a,ll b)
{
if(dsu[a][b]<=1e4)
return b;
return dsu[a][b]=fnd(a,dsu[a][b]);
}
int main()
{
//freopen("input16.txt","r",stdin);
//freopen("output16.txt","w",stdout);
int n,m,i,j,k,a,b,c,x,y,z,l,r,p,q,sz=340;
scl(n);
for(i=0;i<=300;i++){
nxt[i]=10000+340+1;
}
for(i=1;i<=n;i++){
scl(ara[i]);
a=i/sz;
b=i%sz;
b++;
b+=1e4;
c=ara[i];
if(track[a][c]==0){
track[a][c]=nxt[a];
dsu[a][nxt[a]]=c;
nxt[a]++;
}
dsu[a][b]=track[a][c];
}
ll qq;
scl(qq);
ll t;
for(t=1;t<=qq;t++)
{
scl(l);
scl(r);
scl(p);
scl(q);
if(p==q){
continue;
}
//cout<<t<< " "<<l<< " " <<r<< " " <<p<< " " <<q<<endl;
x=l/sz;
y=r/sz;
if(track[x][q]==0 || track[y][q]==0)
{
if(track[x][q]==0){
track[x][q]=nxt[x];
dsu[x][nxt[x]]=q;
nxt[x]++;
}
if(track[y][q]==0){
track[y][q]=nxt[y];
dsu[y][nxt[y]]=q;
nxt[y]++;
}
//nxt++;
}
for(i=l;i<=r && i/sz==x && i<=n;i++)
{
k=i%sz;
k+=10001;
a=fnd(x,k);
b=dsu[x][a];
if(b!=p)
continue;
dsu[x][k]=track[x][q];
}
//cout<<t<< " " <<qq<<endl;
if(x==y)
continue;
for(i=r;i>0 && i/sz==y;i--)
{
k=i%sz;
k+=10001;
a=fnd(y,k);
b=dsu[y][a];
if(b!=p)
continue;
dsu[y][k]=track[y][q];
}
for(i=x+1;i<y;i++)
{
if(track[i][p]==0)
continue;
a=track[i][p];
b=track[i][q];
if(b==0){
track[i][q]=a;
dsu[i][a]=q;
}
else{
dsu[i][a]=b;
}
track[i][p]=0;
}
//cout<<t<<" "<<q<<endl;
}
for(i=1;i<=n;i++)
{
a=i/sz;
b=i%sz;
b+=10001;
c=fnd(a,b);
c=dsu[a][c];
printf("%d",c);
if(i<n)
printf(" ");
}
cout<<endl;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBzY2wobikgc2NhbmYoIiVkIiwmbikKI2RlZmluZSBsbCBpbnQKCmludCBkc3VbMzAyXVsxMTUwMDBdLGFyYVsxMDAwMDVdLG54dFszMDJdLHRyYWNrWzMwMl1bMTAwMDJdOwoKaW50IGZuZChsbCBhLGxsIGIpCnsKICAgIGlmKGRzdVthXVtiXTw9MWU0KQogICAgICAgIHJldHVybiBiOwogICAgcmV0dXJuIGRzdVthXVtiXT1mbmQoYSxkc3VbYV1bYl0pOwp9CgppbnQgbWFpbigpCnsKICAgIC8vZnJlb3BlbigiaW5wdXQxNi50eHQiLCJyIixzdGRpbik7CiAgICAvL2ZyZW9wZW4oIm91dHB1dDE2LnR4dCIsInciLHN0ZG91dCk7CiAgICBpbnQgbixtLGksaixrLGEsYixjLHgseSx6LGwscixwLHEsc3o9MzQwOwogICAgc2NsKG4pOwogICAgZm9yKGk9MDtpPD0zMDA7aSsrKXsKICAgICAgICBueHRbaV09MTAwMDArMzQwKzE7CiAgICB9CiAgICBmb3IoaT0xO2k8PW47aSsrKXsKICAgICAgICBzY2woYXJhW2ldKTsKICAgICAgICBhPWkvc3o7CiAgICAgICAgYj1pJXN6OwogICAgICAgIGIrKzsKICAgICAgICBiKz0xZTQ7CiAgICAgICAgYz1hcmFbaV07CiAgICAgICAgaWYodHJhY2tbYV1bY109PTApewogICAgICAgICAgICB0cmFja1thXVtjXT1ueHRbYV07CiAgICAgICAgICAgIGRzdVthXVtueHRbYV1dPWM7CiAgICAgICAgICAgIG54dFthXSsrOwogICAgICAgIH0KICAgICAgICBkc3VbYV1bYl09dHJhY2tbYV1bY107CiAgICB9CiAgICBsbCBxcTsKICAgIHNjbChxcSk7CiAgICBsbCB0OwogICAgZm9yKHQ9MTt0PD1xcTt0KyspCiAgICB7CiAgICAgICAgc2NsKGwpOwogICAgICAgIHNjbChyKTsKICAgICAgICBzY2wocCk7CiAgICAgICAgc2NsKHEpOwogICAgICAgIGlmKHA9PXEpewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgLy9jb3V0PDx0PDwgIiAiPDxsPDwgIiAiIDw8cjw8ICIgIiA8PHA8PCAiICIgPDxxPDxlbmRsOwogICAgICAgIHg9bC9zejsKICAgICAgICB5PXIvc3o7CiAgICAgICAgaWYodHJhY2tbeF1bcV09PTAgfHwgdHJhY2tbeV1bcV09PTApCiAgICAgICAgewogICAgICAgICAgICBpZih0cmFja1t4XVtxXT09MCl7CiAgICAgICAgICAgICAgICB0cmFja1t4XVtxXT1ueHRbeF07CiAgICAgICAgICAgICAgICBkc3VbeF1bbnh0W3hdXT1xOwogICAgICAgICAgICAgICAgbnh0W3hdKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYodHJhY2tbeV1bcV09PTApewogICAgICAgICAgICAgICAgdHJhY2tbeV1bcV09bnh0W3ldOwogICAgICAgICAgICAgICAgZHN1W3ldW254dFt5XV09cTsKICAgICAgICAgICAgICAgIG54dFt5XSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vbnh0Kys7CiAgICAgICAgfQogICAgICAgIGZvcihpPWw7aTw9ciAmJiBpL3N6PT14ICYmIGk8PW47aSsrKQogICAgICAgIHsKICAgICAgICAgICAgaz1pJXN6OwogICAgICAgICAgICBrKz0xMDAwMTsKICAgICAgICAgICAgYT1mbmQoeCxrKTsKICAgICAgICAgICAgYj1kc3VbeF1bYV07CiAgICAgICAgICAgIGlmKGIhPXApCiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgZHN1W3hdW2tdPXRyYWNrW3hdW3FdOwoKCiAgICAgICAgfQogICAgICAgIC8vY291dDw8dDw8ICIgIiA8PHFxPDxlbmRsOwogICAgICAgIGlmKHg9PXkpCiAgICAgICAgICAgIGNvbnRpbnVlOwoKICAgICAgICBmb3IoaT1yO2k+MCAmJiBpL3N6PT15O2ktLSkKICAgICAgICB7CiAgICAgICAgICAgIGs9aSVzejsKICAgICAgICAgICAgays9MTAwMDE7CiAgICAgICAgICAgIGE9Zm5kKHksayk7CiAgICAgICAgICAgIGI9ZHN1W3ldW2FdOwogICAgICAgICAgICBpZihiIT1wKQogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIGRzdVt5XVtrXT10cmFja1t5XVtxXTsKICAgICAgICB9CgogICAgICAgIGZvcihpPXgrMTtpPHk7aSsrKQogICAgICAgIHsKICAgICAgICAgICAgaWYodHJhY2tbaV1bcF09PTApCiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgYT10cmFja1tpXVtwXTsKICAgICAgICAgICAgYj10cmFja1tpXVtxXTsKICAgICAgICAgICAgaWYoYj09MCl7CiAgICAgICAgICAgICAgICB0cmFja1tpXVtxXT1hOwogICAgICAgICAgICAgICAgZHN1W2ldW2FdPXE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIGRzdVtpXVthXT1iOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRyYWNrW2ldW3BdPTA7CiAgICAgICAgfQogICAgICAgIC8vY291dDw8dDw8IiAgICI8PHE8PGVuZGw7CiAgICB9CgogICAgZm9yKGk9MTtpPD1uO2krKykKICAgIHsKICAgICAgICBhPWkvc3o7CiAgICAgICAgYj1pJXN6OwogICAgICAgIGIrPTEwMDAxOwogICAgICAgIGM9Zm5kKGEsYik7CiAgICAgICAgYz1kc3VbYV1bY107CiAgICAgICAgcHJpbnRmKCIlZCIsYyk7CiAgICAgICAgaWYoaTxuKQogICAgICAgICAgICBwcmludGYoIiAiKTsKICAgIH0KICAgIGNvdXQ8PGVuZGw7Cgp9Cg==