(https://www.luogu.com.cn/problem/B4041)
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[1010101],q,l,r;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-48;
ch=getchar();
}
return x*f;
}
inline void write(int x){
if(x>9)
write(x/10);
if(x<0){
putchar('-');
x=-x;
}
putchar(x%10+48);
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
n=read();
for(int i=1;i<=n;i++)
a[i]=read();
q=read();
while(q--){
cin>>l>>r;
for(int i=l;i<r;i++)
for(int j=i+1;j<=r;j++)
if(a[i]>a[j])
swap(a[i],a[j]);
}
for(int i=1;i<=n;i++){
write(a[i]);
putchar(' ');
}
return 0;
}