#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)< P; typedef pair pll; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector vd; typedef vector

vp; typedef vector vs; const int MAX_N = 100005; ll add(ll x,ll y) { return (x + y)%MOD; } ll sub(ll x,ll y) { return (x+MOD-y)%MOD; } ll mul(ll x,ll y) { return x*y%MOD; } struct monoid { ll a,b,c; int type; monoid(){}; monoid(ll x,ll y,ll z,int flag) : a(x), b(y), c(z), type(flag){}; monoid operator*(const monoid& another){ if(this->type == 2 || another.type == 2){ if(this->type == 2){ if(another.type == 2){ return monoid(0,0,0,2); }else{ return monoid(another.a,another.b,another.c,another.type); } }else{ return monoid(this->a,this->b,this->c,this->type); } } if(this->type==0){ if(another.type==0){ return monoid(this->a,add(add(this->b,mul(this->c,another.a)),another.b),another.c,0); }else{ return monoid(this->a,this->b,mul(this->c,another.a),0); } }else{ if(another.type==0){ return monoid(mul(this->a,another.a),another.b,another.c,0); }else{ return monoid(mul(this->a,another.a),0,0,1); } } } }; template class segtree { private: int n,sz; vector node; public: segtree(vector& v){ sz = (int)v.size(); n = 1; while(n < sz){ n *= 2; } node.resize(2*n-1); rep(i,sz){ node[i+n-1] = v[i]; } for(int i=n-2; i>=0; i--){ node[i] = node[i*2+1]*node[i*2+2]; } } void update(int k,V a) { k += n-1; node[k] = a; while(k>0){ k = (k-1)/2; node[k] = node[2*k+1]*node[2*k+2]; } } V query(int a,int b,int k=0,int l=0,int r=-1) { if(r < 0) r = n; if(r <= a || b <= l){ return monoid(0,0,0,2); } if(a <= l && r <= b){ return node[k]; }else{ V vl = query(a,b,2*k+1,l,(l+r)/2); V vr = query(a,b,2*k+2,(l+r)/2,r); return vl*vr; } } void print() { rep(i,sz){ cout << query(i,i+1) << " "; } cout << endl; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vs s(n); rep(i,n){ cin >> s[i]; } vector vec(n); for(int i=1;i sg(vec); int q; cin >> q; rep(i,q){ string t; int x,y; cin >> t >> x >> y; --x,--y; if(t == "!"){ if(x % 2 == 1){ monoid xx,yy; if(s[y] == "*"){ xx = monoid(stoi(s[x+1]),0,0,1); }else{ xx = monoid(1,0,stoi(s[x+1]),0); } if(s[x] == "*"){ yy = monoid(stoi(s[y+1]),0,0,1); }else{ yy = monoid(1,0,stoi(s[y+1]),0); } sg.update((x-1)/2,xx); sg.update((y-1)/2,yy); }else{ monoid xx,yy; if(s[x-1] == "*"){ xx = monoid(stoi(s[y]),0,0,1); }else{ xx = monoid(1,0,stoi(s[y]),0); } if(s[y-1] == "*"){ yy = monoid(stoi(s[x]),0,0,1); }else{ yy = monoid(1,0,stoi(s[x]),0); } sg.update((x-1)/2,xx); sg.update((y-1)/2,yy); } swap(s[x],s[y]); }else{ monoid res = sg.query(x/2,y/2); cout << add(mul(stoi(s[x]),res.a),add(res.b,res.c)) << "\n"; } } return 0; }