#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; const int MO = (int)1e9 + 7; int N, n; string op="+"; vi va; const int R = 1 << 18 | 1; vi z[R]; vi mrg(vi &a, vi &b, char o) { if (!sz(a))return b; if (!sz(b))return a; vi r; r.reserve(6); each(x, a)r.push_back(x); if (o == '+') { r.push_back(b[0]); } else { r.back() = (ll)r.back() * b[0] % MO; } FOR(i, 1, sz(b))r.push_back(b[i]); if (sz(r) > 3)swap(r[2], r.back()); while (sz(r) > 3) { (r[1] += r.back()) %= MO; r.pop_back(); } return r; } void upd(int k, int l, int r, int idx, int val, char o) { if (r - l == 1) { z[k][0] = val; va[l] = val; op[l] = o; return; } int kl = 2 * k + 1; int kr = 2 * k + 2; int m = (l + r) >> 1; if (idx < m)upd(kl, l, m, idx, val, o); else upd(kr, m, r, idx, val, o); z[k] = mrg(z[kl], z[kr], op[m]); } vi query(int k, int l, int r, int x, int y) { if (r <= x || l >= y)return vi(0); if (x <= l && r <= y) return z[k]; int kl = 2 * k + 1; int kr = 2 * k + 2; int m = (l + r) >> 1; vi a = query(kl, l, m, x, y); vi b = query(kr, m, r, x, y); return mrg(a, b, op[m]); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> N; rep(i, N) { char c; cin >> c; if (i & 1)op += c; else va.push_back(c - '0'); } N = 1; while (N < sz(op))N *= 2; while (sz(op) < N) { op += '+'; va.push_back(0); } rep(i, 2 * N + 1) { z[i].reserve(6); z[i].push_back(0); } rep(i, N) { upd(0, 0, N, i, va[i], op[i]); } int Q; cin >> Q; while (Q--) { char T; int X, Y; cin >> T >> X >> Y; if (T == '!') { int md = X % 2; X /= 2; Y /= 2; if (md == 1) { // num int vx = va[X], vy = va[Y]; upd(0, 0, N, X, vy, op[X]); upd(0, 0, N, Y, vx, op[Y]); } else { char ox = op[X], oy = op[Y]; upd(0, 0, N, X, va[X], oy); upd(0, 0, N, Y, va[Y], ox); } } else { X /= 2; Y = Y / 2 + 1; ll ans = 0; auto w = query(0, 0, N, X, Y); each(x, w)ans += x; cout << ans%MO << endl; } } }