#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair P; const int MAX_N=1<<17; const ll MOD=1e9+7; int n; char c[100001]; set ind; int m; ll prod[2*MAX_N]; void init(int m_){ m=1; while(m=1; i--){ prod[i]=prod[2*i]*prod[2*i+1]%MOD; } } void update(int k, ll a){ k+=m; prod[k]=a; while(k>1){ k>>=1; prod[k]=prod[2*k]*prod[2*k+1]%MOD; } } ll query(int a, int b){ a+=m, b+=m; ll ans=1; for(;a>=1, b>>=1){ if(b&1) ans=ans*prod[--b]%MOD; if(a&1) ans=ans*prod[a++]%MOD; } return ans; } ll bit[100001]; ll sump[100001]; ll sum(int i){ ll s=0; while(i>0){ s+=bit[i]; s%=MOD; i-=(i&(-i)); } return s; } void add(int i, ll x){ while(i<=n){ bit[i]+=x; bit[i]%=MOD; i+=(i&(-i)); } } int main() { cin>>n; for(int i=1; i<=n; i++){ cin>>c[i]; if(c[i]=='+') ind.insert(i); } init(n+1); int l=1; for(int i=2; i<=n; i+=2){ if(c[i]=='+'){ sump[l]=query(l, i); l=i+1; } } sump[l]=query(l, n+1); int q; cin>>q; for(int i=0; i>t>>x>>y; if(t=='!'){ if(x&1){ ll xc=prod[x+m], yc=prod[y+m]; update(x, yc); update(y, xc); auto itr=ind.lower_bound(x); int l, r; if(itr==ind.end()) r=n+1; else r=*itr; if(ind.empty() || itr==ind.begin()) l=1; else{ itr--; l=(*itr)+1; } ll s1=query(l, r); add(l, (s1-sump[l]+MOD)%MOD); sump[l]=s1; itr=ind.lower_bound(y); if(itr==ind.end()) r=n+1; else r=*itr; if(ind.empty() || itr==ind.begin()) l=0; else{ itr--; l=(*itr)+1; } s1=query(l, r); add(l, (s1-sump[l]+MOD)%MOD); sump[l]=s1; }else{ if(c[x]==c[y]) continue; if(c[x]=='+') swap(x, y); c[x]='+'; auto itr=ind.lower_bound(x); int l, r; if(itr==ind.end()) r=n+1; else r=*itr; if(ind.empty() || itr==ind.begin()) l=1; else{ itr--; l=(*itr)+1; } ll s1=query(l, x); add(l, (s1-sump[l]+MOD)%MOD); sump[l]=s1; s1=query(x, r); add(x+1, (s1-sump[x+1]+MOD)%MOD); sump[x+1]=s1; ind.insert(x); c[y]='*'; itr=ind.lower_bound(y); itr++; if(itr==ind.end()) r=n+1; else r=*itr; itr--; if(itr==ind.begin()) l=1; else{ itr--; l=(*itr)+1; } add(y+1, (MOD-sump[y+1])%MOD); sump[y+1]=0; s1=query(l, r); add(l, (s1-sump[l]+MOD)%MOD); sump[l]=s1; ind.erase(y); } }else{ auto itr1=ind.lower_bound(x), itr2=ind.lower_bound(y); if(itr1==itr2){ cout<