#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct SegmentTree{ using F = function; using G = function; int n; F f; G g; T ti; vector dat; SegmentTree(){}; SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){} void init(int n_){ n=1; while(n &v){ int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } void set_val(int k,T x){ dat[k+=n]=x; while(k>>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } T query(int a,int b){ T vl=ti,vr=ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } }; struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; template struct Mint{ T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;}; Mint operator-(Mint a) const{return Mint(v)-=a;}; Mint operator*(Mint a) const{return Mint(v)*=a;}; Mint operator/(Mint a) const{return Mint(v)/=a;}; Mint operator-(){return v?MOD-v:v;} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v >n; n=(n+1)/2; vector v(n); vector c(n); c[0]='+'; for(int i=0;i>c[i]; cin>>v[i]; } using M = Mint; struct T{ int t; M a,b,c; T(){} T(int t,M a,M b,M c):t(t),a(a),b(b),c(c){} bool operator==(const T &o)const{ return t==o.t&&a==o.a&&b==o.b&&c==o.c; } }; T ti(-1,0,0,0); auto f=[&](T a,T b){ if(a==ti) return b; if(ti==b) return a; if(a.t==0) return T(b.t,a.a*b.a,b.b,b.c); if(b.t==0) return T(a.t,a.a,a.b,a.c*b.a); return T(a.t,a.a,a.b+a.c*b.a+b.b,b.c); }; auto g=[&](T a,T b){a.t++;return b;}; SegmentTree seg(f,g,ti); vector vt(n); for(int i=0;i>q; for(int i=0;i>t>>x>>y; if(t=='!'){ int k=x&1; x>>=1;y>>=1; if(k) swap(v[x],v[y]); else swap(c[x],c[y]); for(int i:{x,y}){ if(c[i]=='*') vt[i]=T(0,v[i],0,0); if(c[i]=='+') vt[i]=T(1,1,0,v[i]); seg.update(i,vt[i]); } } if(t=='?'){ x>>=1;y>>=1; auto z=seg.query(x,y+1); if(c[x]=='*') cout<<(z.a+z.b+z.c).v<<"\n"; if(c[x]=='+') cout<<(z.b+z.c).v<<"\n"; } } cout<