#include<bits/stdc++.h>
using namespace std;
struct node{
int n,m;
int v[4][4];
void init(){
n=3,m=3;
v[1][1]=0,v[1][2]=-1e9,v[1][3]=-1e9;
v[2][1]=-1e9,v[2][2]=0,v[2][3]=-1e9;
v[3][1]=-1e9,v[3][2]=-1e9,v[3][3]=0;
}
};
node operator*(node a,node b){
node c;
c.n=a.n,c.m=b.m;
for(int i=1;i<=a.n;i++){
for(int j=1;j<=b.m;j++){
c.v[i][j]=-1e9;
for(int k=1;k<=a.m;k++){
c.v[i][j]=max(c.v[i][j],a.v[i][k]+b.v[k][j]);
}
}
}
return c;
}
node a[100010];
struct tag_tree{
node maxn,tag;
}tree[400010];
void push_up(int p){
tree[p].maxn.v[1][1]=max(tree[p<<1].maxn.v[1][1],tree[p<<1|1].maxn.v[1][1]);
tree[p].maxn.v[2][1]=max(tree[p<<1].maxn.v[2][1],tree[p<<1|1].maxn.v[2][1]);
tree[p].maxn.v[3][1]=0;
}
void build(int p,int l,int r){
if(l==r){
tree[p].maxn.n=3,tree[p].maxn.m=1;
tree[p].maxn.v[1][1]=a[l].v[1][1];
tree[p].maxn.v[2][1]=a[l].v[2][1];
tree[p].maxn.v[3][1]=0;
tree[p].tag.init();
return;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
tree[p].maxn.n=3,tree[p].maxn.m=1;
tree[p].tag.init();
push_up(p);
}
int L,R;
node W;
void push_down(int p){
tree[p<<1].tag=tree[p<<1].tag*tree[p].tag;
tree[p<<1|1].tag=tree[p<<1|1].tag*tree[p].tag;
tree[p<<1].maxn=tree[p].tag*tree[p<<1].maxn;
tree[p<<1|1].maxn=tree[p].tag*tree[p<<1|1].maxn;
tree[p].tag.init();
}
int ask1(int p,int l,int r){
if(l>R||r<L)return -1e9;
if(l>=L&&r<=R)return tree[p].maxn.v[1][1];
push_down(p);
int mid=(l+r)>>1;
return max(ask1(p<<1,l,mid),ask1(p<<1|1,mid+1,r));
}
int ask2(int p,int l,int r){
if(l>R||r<L)return -1e9;
if(l>=L&&r<=R)return tree[p].maxn.v[2][1];
push_down(p);
int mid=(l+r)>>1;
return max(ask2(p<<1,l,mid),ask2(p<<1|1,mid+1,r));
}
void change1(int p,int l,int r){
if(l>R||r<L)return;
if(l>=L&&r<=R){
tree[p].maxn=W*tree[p].maxn;
tree[p].tag=W*tree[p].tag;
return;
}
push_down(p);
int mid=(l+r)>>1;
change1(p<<1,l,mid);
change1(p<<1|1,mid+1,r);
push_up(p);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(),cout.tie();
int n;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
a[i].n=3,a[i].m=1;
a[i].v[1][1]=x;
a[i].v[2][1]=x;
a[i].v[3][1]=0;
}
build(1,1,n);
int m;
cin>>m;
while(m--){
char opt;
cin>>opt>>L>>R;
if(opt=='Q'){
cout<<ask1(1,1,n)<<"\n";
}
else if(opt=='A'){
cout<<ask2(1,1,n)<<"\n";
}
else if(opt=='P'){
int x;
cin>>x;
W.n=W.m=3;
W.v[1][1]=x,W.v[1][2]=-1e9,W.v[1][3]=-1e9;
W.v[2][1]=x,W.v[2][2]=0,W.v[2][3]=-1e9;
W.v[3][1]=-1e9,W.v[3][2]=-1e9,W.v[3][3]=0;
change1(1,1,n);
}
else{
int x;
cin>>x;
W.n=W.m=3;
W.v[1][1]=-1e9,W.v[1][2]=-1e9,W.v[1][3]=x;
W.v[2][1]=-1e9,W.v[2][2]=0,W.v[2][3]=x;
W.v[3][1]=-1e9,W.v[3][2]=-1e9,W.v[3][3]=0;
change1(1,1,n);
}
}
return 0;
}