#include using namespace std; typedef long long ll; const int MM = 1e9 + 7; const int MAXN = 2e6 + 10; int n, m, M, Q; char s[100]; ll a[MAXN]; int L[MAXN], R[MAXN]; const int MAKI = 9; struct node{ int tp, nxt; ll a, b, c; } rst[MAXN], nico; void merge(node &ru, node rl, node rr){ ru.nxt = rr.nxt; if (rl.tp == 1){ if (rr.tp == 1){ if (rl.nxt == -2){ ru.tp = 1; ru.a = rl.a * rr.a % MM; } else{ ru.tp = 2; ru.a = rl.a; ru.b = 0; ru.c = rr.a; } } else{ if (rl.nxt == -2){ ru.tp = 2; ru.a = rl.a * rr.a % MM; ru.b = rr.b; ru.c = rr.c; } else{ ru.tp = 2; ru.a = rl.a; ru.b = rr.a + rr.b; ru.c = rr.c; } } } else{ if (rr.tp == 1){ if (rl.nxt == -2){ ru.tp = 2; ru.a = rl.a; ru.b = rl.b; ru.c = rl.c * rr.a % MM; } else{ ru.tp = 2; ru.a = rl.a; ru.b = rl.b + rl.c; ru.c = rr.a; } } else{ if (rl.nxt == -2){ ru.tp = 2; ru.a = rl.a; ru.b = (rl.b + rl.c * rr.a + rr.b) % MM; ru.c = rr.c; } else{ ru.tp = 2; ru.a = rl.a; ru.b = (rl.b + rl.c + rr.a + rr.b) % MM; ru.c = rr.c; } } } } void update(int u){ int l = u << 1; int r = l | 1; merge(rst[u], rst[l], rst[r]); } node query(int u, int L, int R, int l, int r){ if (L == l && R == r) return rst[u]; int m = (L + R) / 2; if (r <= m) return query(u * 2, L, m, l, r); else if (l > m) return query(u * 2 + 1, m + 1, R, l, r); else{ node f; merge(f, query(u*2,L,m,l,m), query(u*2+1,m+1,R,m+1,r)); return f; } } int main(){ scanf("%d", &n); for (int i = 1; i <= n; i++){ scanf("%s", s); if (s[0] == '+') a[i] = -1; else if (s[0] == '*') a[i] = -2; else a[i] = s[0] - '0'; } a[++n] = -1; for(M=1;M= 1; i--){ update(i); } scanf("%d", &Q); while(Q--){ int x, y; scanf("%s", s); scanf("%d%d", &x, &y); if (s[0] == '?'){ nico = query(1, 1, M, (x+1)/2, (y+1)/2); if (nico.tp == 1) printf("%lld\n", nico.a); else printf("%lld\n", (nico.a+nico.b+nico.c)%MM); } else{ swap(a[x], a[y]); if(x&1)rst[(x+1)/2+M-1].a=a[x];else rst[(x+1)/2+M-1].nxt=a[x]; for (int i = ((x+1)/2+M-1)/2; i >= 1; i /= 2) update(i); if(y&1)rst[(y+1)/2+M-1].a=a[y];else rst[(y+1)/2+M-1].nxt=a[y]; for (int i = ((y+1)/2+M-1)/2; i >= 1; i /= 2) update(i); /* puts("=================="); printf("%s %d %d\n", s, x, y); for (int l = 1, r = 1; l <= M; l = r + 1, r = l * 2 - 1){ for (int i = l; i <= r; i++){ printf("[%d %d %lld %lld %lld], ", rst[i].tp, rst[i].nxt, rst[i].a, rst[i].b, rst[i].c); } puts(""); } */ } } return 0; }