#include using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(int i = (l) ; i < (r); i++) #define incII(i, l, r) for(int i = (l) ; i <= (r); i++) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--) #define decII(i, l, r) for(int i = (r) ; i >= (l); i--) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define PQ priority_queue #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define FOR(it, v) for(auto it = v.begin(); it != v.end(); ++it) #define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it) template bool setmin(T & a, T b) { if(b < a) { a = b; return true; } else { return false; } } template bool setmax(T & a, T b) { if(b > a) { a = b; return true; } else { return false; } } template bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } } template bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } } template T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template T lcm(T a, T b) { return a / gcd(a, b) * b; } // ---- ---- template class SegTree { private: T * a = NULL; int M, S; T (*F)(T, T); T I; public: // [0, size) が使用可能になる、func が演算、id は単位元 void init(int size, T (*func)(T, T), T id) { assert(size > 0); M = size; F = func; I = id; S = 1; while(S < size) { S *= 2; } delete[] a; a = new T[S * 2]; inc(i, S * 2) { a[i] = I; } } // 参照(値を変更した後は calc() を呼ぶこと) T & operator[](int p) { assert(inID(p, 0, M)); p += S; return a[p]; } // テーブルの再計算 void calc() { decID(i, 1, S) { a[i] = F(a[i * 2], a[i * 2 + 1]); } } // a[p] を v に変更し再計算 void update(int p, T v) { assert(inID(p, 0, M)); p += S; a[p] = v; while(p != 1) { p /= 2; a[p] = F(a[p * 2], a[p * 2 + 1]); } } // [l, r) に f を適用した結果を返す T range(int l, int r) { assert(inII(l, 0, M)); assert(inII(r, 0, M)); // if(l > r) { return F(range(l, M), range(0, r)); } assert(l <= r); l += S; r += S; T v = I, w = I; while(l < r) { if(l + 1 == r) { v = F(v, a[l]); break; } if(l % 2 == 1) { v = F(v, a[l]); } if(r % 2 == 1) { w = F(a[r - 1], w); } l = (l + 1) / 2; r = r / 2; } return F(v, w); } }; // ---- ---- ---- ---- typedef array A; LL MOD = 1e9 + 7; A F(A x, A y) { if(x[3] == -1) { return y; } if(y[3] == -1) { return x; } deque qx, qy; inc(i, 3) { if(x[i] != -1) { qx.PB(x[i]); } } inc(i, 3) { if(y[i] != -1) { qy.PB(y[i]); } } if(x[3] == 1) { // '*' LL vx = qx.back(); qx.pop_back(); LL vy = qy.front(); qy.pop_front(); qx.PB(vx * vy % MOD); } for(auto && e: qy) { qx.PB(e); } if(qx.size() == 1) { return { -1, qx[0], -1, y[3] }; } else { LL xf = qx.front(); qx.pop_front(); LL xb = qx.back(); qx.pop_back(); LL sum = 0; for(auto && e: qx) { (sum += e) %= MOD; } return { xf, sum, xb, y[3] }; } } LL val(A a) { LL sum = 0; inc(i, 3) { if(a[i] != -1) { (sum += a[i]) %= MOD; } } return sum; } int n, q; SegTree st; int main() { cin >> n; vector di; vector op; inc(i, n) { string s; cin >> s; if(i % 2 == 0) { di.PB(s[0] - '0'); } else { op.PB(s[0]); } } st.init(di.size(), F, { 0, 0, 0, -1 }); inc(i, di.size()) { st[i] = { -1, di[i], -1, (op[i] == '+' ? 0 : 1) }; } st.calc(); cin >> q; inc(i, q) { string s; int x, y; cin >> s >> x >> y; if(s == "!") { if(x % 2 == 1) { // 数字 x /= 2; y /= 2; swap(st[x][1], st[y][1]); st.update(x, st[x]); st.update(y, st[y]); } else { // 演算子 x = x / 2 - 1; y = y / 2 - 1; swap(st[x][3], st[y][3]); st.update(x + 0, st[x + 0]); st.update(x + 1, st[x + 1]); st.update(y + 0, st[y + 0]); st.update(y + 1, st[y + 1]); } } else { x /= 2; y /= 2; y++; cout << val(st.range(x, y)) << "\n"; } } return 0; }