class SegmentTreeLazy(): def __init__(self, arr, ti, ei, func, op, merge): self.h = (len(arr) - 1).bit_length() self.n = 2**self.h self.func = func self.op = op self.merge = merge self.ti = ti self.ei = ei self.val = [ti for _ in range(2 * self.n)] for i in range(len(arr)): self.val[self.n + i] = arr[i] for i in range(1, self.n)[::-1]: self.val[i] = self.func(self.val[2 * i], self.val[2 * i + 1]) self.laz = [ei for _ in range(2 * self.n)] def reflect(self, k): if self.laz[k] == self.ei: return self.val[k] return self.op(self.val[k], self.laz[k]) def propagate(self, k): if self.laz[k] == self.ei: return self.laz[2 * k] = self.merge(self.laz[2 * k], self.laz[k]) self.laz[2 * k + 1] = self.merge(self.laz[2 * k + 1], self.laz[k]) self.val[k] = self.reflect(k) self.laz[k] = self.ei def thrust(self, k): for i in range(1, self.h + 1)[::-1]: self.propagate(k >> i) def recalc(self, k): while k: k >>= 1 self.val[k] = self.func(self.reflect(2 * k), self.reflect(2 * k + 1)) def update(self, lt, rt, x): lt += self.n rt += self.n vl = lt vr = rt self.thrust(lt) self.thrust(rt - 1) while rt - lt > 0: if lt & 1: self.laz[lt] = self.merge(self.laz[lt], x) lt += 1 if rt & 1: rt -= 1 self.laz[rt] = self.merge(self.laz[rt], x) lt >>= 1 rt >>= 1 self.recalc(vl) self.recalc(vr - 1) def query(self, lt, rt): lt += self.n rt += self.n self.thrust(lt) self.thrust(rt - 1) vl = vr = self.ti while rt - lt > 0: if lt & 1: vl = self.func(vl, self.reflect(lt)) lt += 1 if rt & 1: rt -= 1 vr = self.func(self.reflect(rt), vr) lt >>= 1 rt >>= 1 return self.func(vl, vr) def fibonacci(n, mod=1000000007): res = [0 for _ in range(n + 1)] res[0] = 0 res[1] = 1 for i in range(2, n + 1): res[i] = res[i - 1] + res[i - 2] res[i] %= mod return res import sys input = sys.stdin.buffer.eadline MOD = 1000000007 MODsq = MOD**2 N, Q = map(int, input().split()) F = fibonacci(N) arr = [MOD + F[i] for i in range(N)] ti = 0 ei = MODsq def func(a, b): a3 = a % MOD a2 = (a - a3) // MOD % MOD a1 = (a - a3 - a2 * MOD) // MODsq b3 = b % MOD b2 = (b - b3) // MOD % MOD b1 = (b - b3 - b2 * MOD) // MODsq c1 = (a1 + b1) % MOD c2 = (a2 + b2) % MOD c3 = (a3 + b3) % MOD return c1 * MODsq + c2 * MOD + c3 def op(a, x): a3 = a % MOD a2 = (a - a3) // MOD % MOD a1 = (a - a3 - a2 * MOD) // MODsq x3 = x % MOD x2 = (x - x3) // MOD % MOD x1 = (x - x3 - x2 * MOD) // MODsq c1 = (a1 * x1 + a2 * x2 + a3 * x3) % MOD c2 = a2 % MOD c3 = a3 % MOD return c1 * MODsq + c2 * MOD + c3 def merge(x, y): x3 = x % MOD x2 = (x - x3) // MOD % MOD x1 = (x - x3 - x2 * MOD) // MODsq y3 = y % MOD y2 = (y - y3) // MOD % MOD y1 = (y - y3 - y2 * MOD) // MODsq z1 = (x1 * y1) % MOD z2 = (x2 * y1 + y2) % MOD z3 = (x3 * y1 + y3) % MOD return z1 * MODsq + z2 * MOD + z3 st = SegmentTreeLazy(arr, ti, ei, func, op, merge) res = [] for _ in range(Q): q, l, r, k = map(int, input().split()) if q == 0: x = st.query(l, r + 1) x3 = x % MOD x2 = (x - x3) // MOD % MOD x1 = (x - x3 - x2 * MOD) // MODsq res.append(k * x1 % MOD) elif q == 1: st.update(l, r + 1, k * MOD) elif q == 2: st.update(l, r + 1, MODsq + k * MOD) elif q == 3: st.update(l, r + 1, k * MODsq) else: st.update(l, r + 1, MODsq + k) print('\n'.join(map(str, res)))