#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 UB upper_bound #define LB lower_bound #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)); 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); } }; template T prod(T x, T y) { return x * y; } // ---- ---- ---- ---- const LL MOD = 1000000007; class Matrix { public: LL a[4][4]; Matrix() { inc(i, 4) { inc(j, 4) { a[i][j] = 0; } } } Matrix operator*(const Matrix & m) { Matrix x; inc(i, 4) { inc(j, 4) { inc(k, 4) { (x.a[i][j] += a[i][k] * m.a[k][j]) %= MOD; } } } return x; } }; int main() { int n, q; cin >> n >> q; Matrix id; inc(i, 4) { id.a[i][i] = 1; } SegTree st; st.init(n, prod, id); inc(i, n) { Matrix m; LL a[4][4] = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 1, 0, 0, 0 }, { 1, 0, 0, 0 }, }; inc(j, 4) { inc(k, 4) { m.a[j][k] = a[j][k]; } } st[i] = m; } st.calc(); //////// /* Matrix m = st.range(2, 4); inc(j, 4) { inc(k, 4) { cout << m.a[j][k] << " "; } cout << endl; } cout << endl; */ inc(qq, q) { char c; LL i, v; cin >> c; if(c == 'x') { cin >> i >> v; i = n - 1 - i; Matrix m = st[i]; m.a[1][3] = v; st.update(i, m); } if(c == 'y') { cin >> i >> v; i = n - 1 - i; Matrix m = st[i]; m.a[2][2] = v; m.a[3][2] = 2 * v; m.a[3][3] = (v * v) % MOD; st.update(i, m); } if(c == 'a') { cin >> i; Matrix m = st.range(n - i, n); LL ans = 0; inc(j, 4) { ans += m.a[1][j]; } cout << ans % MOD << "\n"; } } return 0; }