#include using namespace std; typedef long long ll; typedef pair PII; const int MM = 1e9 + 7; const double eps = 1e-8; const int MAXN = 2e6 + 10; int n, m; void prework(){ } void read(){ } char s[100]; ll a[MAXN]; int L[MAXN], R[MAXN]; const int MAKI = 9; struct node{ int tp; ll a, b, c; } rst[MAXN], nico; void Getans(node &ret, int l, int r){ int p = -1, q = -1; for (int i = l + 1; i < r; i += 2) if (a[i] == -1){ if (p == -1) p = i; q = i; } if (p == -1){ ret.tp = 1; ll tmp = 1; for (int i = l; i <= r; i += 2) tmp = (tmp * a[i] % MM); ret.a = tmp; } else{ ret.tp = 2; ll tmp = 1; for (int i = l; i < p; i += 2) tmp = (tmp * a[i] % MM); ret.a = tmp; tmp = 1; for (int i = q + 1; i <= r; i += 2) tmp = tmp * a[i] % MM; ret.c = tmp; ll sum = 0; tmp = 1; for (int i = p + 1; i < q; i += 2){ tmp = tmp * a[i] % MM; if (a[i + 1] == -1){ sum = (sum + tmp) % MM; tmp = 1; } } ret.b = sum; } } void fill_in(int &pos, node &x, int opt){ if (x.tp == 1){ a[pos++] = x.a; a[pos++] = opt; } else{ a[pos++] = x.a; a[pos++] = -1; a[pos++] = x.b; a[pos++] = -1; a[pos++] = x.c; a[pos++] = opt; } } void solve(int casi){ // cout << "Case #" << casi << ": "; int M, Q; 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'; } M = n >> MAKI; for (int i = 0; i <= M; i++){ L[i] = (i << MAKI) + 1; R[i] = ((i + 1) << MAKI) - 1; } L[0] = 1, R[M] = n; for (int i = 0; i <= M; i++) Getans(rst[i], L[i], R[i]); scanf("%d", &Q); while(Q--){ int x, y; scanf("%s", s); scanf("%d%d", &x, &y); int p = x >> MAKI, q = y >> MAKI; if (s[0] == '?'){ int l = n + 2, r = n + 2; if (p == q || p + 1 == q){ Getans(nico, x, y); if (nico.tp == 1) printf("%lld\n", nico.a); else printf("%lld\n", (nico.a+nico.b+nico.c)%MM); } else{ Getans(nico, x, R[p]); fill_in(r, nico, a[R[p] + 1]); for (int i = p + 1; i < q; i++) fill_in(r, rst[i], a[R[i] + 1]); Getans(nico, L[q], y); fill_in(r, nico, -1); r -= 2; Getans(nico, l, r); 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]); Getans(rst[p], L[p], R[p]); Getans(rst[q], L[q], R[q]); } } } void printans(){ } int main(){ // std::ios::sync_with_stdio(false); prework(); int T = 1; // cin>>T; for(int i = 1; i <= T; i++){ read(); solve(i); printans(); } return 0; }