#include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; #define fi first #define se second #define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep(i,n) repl(i,0,n) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<y?x:y) #define mmin(x,y) (x vec; typedef vector mat; mat operator*(const mat& a,const mat& b){ mat res(4,vec(4,0)); rep(k,4){ rep(i,4){ rep(j,4){ (res[i][j]+=a[i][k]*b[k][j])%=mod; } } } return res; } vector dat; int sz; mat e; void init(int n_){ sz=1; while(sz0){ k=(k-1)/2; dat[k]=dat[k*2+2]*dat[k*2+1]; } } mat query(int a,int b,int k=0,int l=0,int r=sz){ if(r<=a||b<=l)return e; if(a<=l&&r<=b)return dat[k]; else{ return query(a,b,k*2+2,(l+r)/2,r)*query(a,b,k*2+1,l,(l+r)/2); } } int n,q; vector cs; ll pls[4][4]={ {1, 0, 1, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 1}, }; ll mul[4][4]={ {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}, }; ll num[4][4]={ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 10, 0}, {0, 0, 0, 1}, }; int main(){ cin>>n; rep(i,n){ char c; cin>>c; cs.push_back(c); } init(n); rep(i,n){ mat m(4,vec(4,0)); if(isdigit(cs[i])){ rep(j,4)rep(k,4)m[j][k]=num[j][k]; m[2][1]=cs[i]-'0'; }else if(cs[i]=='+'){ rep(j,4)rep(k,4)m[j][k]=pls[j][k]; }else if(cs[i]=='*'){ rep(j,4)rep(k,4)m[j][k]=mul[j][k]; } update(i,m); } mat mpls(4,vec(4,0)); rep(i,4)rep(j,4)mpls[i][j]=pls[i][j]; cin>>q; while(q--){ char typ; cin>>typ; if(typ=='?'){ int l,r; cin>>l>>r; l--; mat m=query(l,r); m=mpls*m; cout<<(m[0][1]+m[0][3])%mod<>i>>j; i--;j--; mat m1=query(i,i+1); mat m2=query(j,j+1); update(i,m2); update(j,m1); } } return 0; }