#include #include #include #include #include const int mod = 1e9 + 7; #ifdef __linux__ #define getchar getchar_unlocked #define putchar putchar_unlocked #endif char readChar() { int c; while ((c = getchar()) < 'a'); return c; } int readInt() { int n, c; while ((c = getchar()) < '0'); n = c - '0'; while ((c = getchar()) >= '0') { n = n * 10 + c - '0'; } return n; } void writeInt(int n) { int d[11]; int i = 0; do { d[i++] = n % 10; n /= 10; } while (n > 0); while (i > 0) { putchar(d[--i] + '0'); } putchar('\n'); } // stupid... struct foo { long long a, b, c, d, e, f, g, h; }; foo operator*(const foo &x, const foo &y) { foo ret; ret.a = (y.a + x.a * y.d + x.b * y.f) % mod; ret.b = (y.b + x.b * y.g) % mod; ret.c = (x.c + y.c + x.a * y.e + x.b * y.h) % mod; ret.d = x.d * y.d % mod; ret.e = (x.e + x.d * y.e) % mod; ret.f = (x.d * y.f + y.f * x.g) % mod; ret.g = x.g * y.g % mod; ret.h = (y.e * x.f + x.h + x.g * y.h) % mod; return ret; } foo getmat(long long x, long long y) { foo c; c.a = 0; c.b = x; c.c = 0; c.d = y; c.e = 1; c.f = 2 * y % mod; c.g = y * y % mod; c.h = 1; return c; } int main() { int n = readInt(); int q = readInt(); std::vector xs(n); std::vector ys(n); int N = 1; while (N < n) { N *= 2; } std::vector seg(N * 2, getmat(0, 0)); auto setval = [&](int k, foo v) { k += N; seg[k] = v; while (k > 1) { k /= 2; seg[k] = seg[k * 2 + 1] * seg[k * 2]; } }; auto getval = [&](int k) { if (k == N) { return seg[1]; } k += N; foo ret = {}; ret.d = 1; ret.g = 1; while (k > 1) { if (k & 1) { ret = ret * seg[k - 1]; } k /= 2; } return ret; }; while (q--) { char c = readChar(); if (c == 'x') { int i = readInt(); int v = readInt(); xs[i] = v; setval(i, getmat(xs[i], ys[i])); } else if (c == 'y') { int i = readInt(); int v = readInt(); ys[i] = v; setval(i, getmat(xs[i], ys[i])); } else { int i = readInt(); auto m = getval(i); writeInt((m.a + m.b + m.c + 1) % mod); } } }