#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define pcnt __builtin_popcount #define show(x) cout<<#x<<" = "< pii; typedef vector vi; typedef vector vvi; typedef vector vpii; typedef set si; typedef pair pll; typedef vector vl; typedef vector vvl; typedef vector vpll; typedef set sl; typedef __int128_t lll; typedef pair plll; typedef vector vlll; templatestring join(vector&v) {stringstream s;FOR(i,0,sz(v))s<<' '<b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;} int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;} void dout(double d){printf("%.12f\n",d);} const int iinf = 1e9; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; typedef pair tll; struct SegTree{ tll e = tll(-1, mp(-1, -1)); int n; vector d; vi id, idi; vector bl; tll merge(tll a, tll b, int c){ if(a.se.fi == -1) return b; if(b.se.fi == -1) return a; if(a.fi == -1){ if(b.fi == -1){ return (bl[id[c]] ? tll(-1, pll(a.se.fi * b.se.fi % mod, -1)) : tll(a.se.fi, pll(0, b.se.fi))); }else{ return (bl[id[c]] ? mp(a.se.fi * b.fi % mod, b.se) : mp(a.se.fi, mp((b.fi + b.se.fi) % mod, b.se.se))); } }else{ if(b.fi == -1){ return (bl[id[c]] ? mp(a.fi, mp(a.se.fi, a.se.se * b.se.fi % mod)) : mp(a.fi, mp((a.se.fi + a.se.se) % mod, b.se.fi))); }else{ return (bl[id[c]] ? mp(a.fi, mp((a.se.fi + a.se.se * b.fi + b.se.fi) % mod, b.se.se)) : mp(a.fi, mp((a.se.fi + a.se.se + b.fi + b.se.fi) % mod, b.se.se))); } } } void init(vl&v, vector&vb){ n=1<<(32-__builtin_clz(sz(v)-1)); d.resize(2*n-1); id.resize(2*n-1); idi.resize(n); bl.resize(2*n-1); fill(rng(d), e); FOR(j,0,sz(v)) d[j+n-1]=tll(-1, pll(v[j], -1)); FOR(j,0,sz(v)) id[j+n-1]=j; FOR(j,0,sz(vb)) bl[j]=vb[j]; FORR(k, n-2, 0){ id[k] = (id[k*2+1] + id[k*2+2]) / 2; idi[id[k]] = k; d[k] = merge(d[k*2+1], d[k*2+2], k); } } void update_ope(int k){ k = idi[k]; while(true){ d[k] = merge(d[k*2+1], d[k*2+2], k); if(k <= 0) break; k=(k-1)/2; } } void update_num(int k){ while(k > 0){ k = (k-1)/2; d[k] = merge(d[k*2+1], d[k*2+2], k); } } tll q(int a,int b,int k,int l,int r){ return (r<=a||b<=l)?e:(a<=l&&r<=b)?d[k]:merge(q(a,b,k*2+1,l,(l+r)/2),q(a,b,k*2+2,(l+r)/2,r), k); } tll query(int a,int b){ return q(a,b,0,0,n); } }; int n, q, x, y; char c; vl v; vector b; tll r; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n; SegTree seg; FOR(i, 0, n){ cin >> c; if(i%2){ b.pb(c=='*'); }else{ v.pb(c-'0'); } } seg.init(v, b); cin >> q; FOR(j, 0, q){ cin >> c >> x >> y; if(c == '!'){ if(x%2){ x/= 2; y/=2; x += seg.n-1; y += seg.n-1; swap(seg.d[x], seg.d[y]); seg.update_num(x); seg.update_num(y); }else{ x--; y--; x/= 2; y/=2; swap(seg.bl[x], seg.bl[y]); seg.update_ope(x); seg.update_ope(y); } }else{ r = seg.query(x/2, y/2+1); cout << (r.fi < 0 ? (r.se.fi) : (r.fi+r.se.fi+r.se.se)%mod) << "\n"; } } return 0; }