#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 86;
const int MOD = 1000000007;
int C[6][6];
int p[MAXN][6];
int s[MAXN][6];
inline int sgn(const int x) { return x & 1 ? -1 : 1; }
void init() {
  for (int i = 0; i < 6; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
  p[0][0] = 1;
  for (int i = 1; i < MAXN; i++) {
    p[i][0] = 1;
    for (int j = 1; j < 6; j++) p[i][j] = (long long)i * p[i][j - 1] % MOD;
    for (int j = 0; j < 6; j++) s[i][j] = (s[i - 1][j] + p[i][j]) % MOD;
  }
}
struct seg_tree {
  int x[MAXN << 2][6];
  int v[MAXN << 2];
  void init() { memset(v, -1, sizeof(v)); }
  void pushup(int rt) {
    for (int i = 0; i < 6; i++)
      x[rt][i] = (x[rt << 1][i] + x[rt << 1 | 1][i]) % MOD;
  }
  void pushdown(int rt, int l, int r) {
    if (v[rt] == -1) return;
    int mid = (l + r) >> 1;
    v[rt << 1] = v[rt << 1 | 1] = v[rt];
    for (int i = 0; i < 6; i++) {
      x[rt << 1][i] = (long long)v[rt] * (s[mid][i] - s[l - 1][i]) % MOD;
      if (x[rt << 1][i] < 0) x[rt << 1][i] += MOD;
      x[rt << 1 | 1][i] = (long long)v[rt] * (s[r][i] - s[mid][i]) % MOD;
      if (x[rt << 1 | 1][i] < 0) x[rt << 1 | 1][i] += MOD;
    }
    v[rt] = -1;
  }
  void modify(int rt, int l, int r, const int L, const int R, const int k) {
    if (L <= l && r <= R) {
      v[rt] = k;
      for (int i = 0; i < 6; i++) {
        x[rt][i] = (long long)k * (s[r][i] - s[l - 1][i]) % MOD;
        if (x[rt][i] < 0) x[rt][i] += MOD;
      }
      return;
    }
    pushdown(rt, l, r);
    int mid = (l + r) >> 1;
    if (L <= mid) modify(rt << 1, l, mid, L, R, k);
    if (R > mid) modify(rt << 1 | 1, mid + 1, r, L, R, k);
    pushup(rt);
  }
  int query(int rt, int l, int r, const int L, const int R, const int k) {
    if (L <= l && r <= R) {
      int tot = 0, off = L - 1;
      for (int j = 0; j <= k; j++) {
        int cc = (long long)C[k][j] * p[off][k - j] % MOD;
        cc = (long long)cc * x[rt][j] * sgn(k - j) % MOD;
        tot = (tot + cc) % MOD;
        if (tot < 0) tot += MOD;
      }
      return tot;
    }
    pushdown(rt, l, r);
    int mid = (l + r) >> 1;
    int c1 = 0, c2 = 0;
    if (L <= mid) c1 = query(rt << 1, l, mid, L, R, k);
    if (R > mid) c2 = query(rt << 1 | 1, mid + 1, r, L, R, k);
    return (c1 + c2) % MOD;
  }
} T;
int main() {
  init();
  T.init();
  int n, m;
  int L, R, x;
  char op[5];
  scanf("%d%d", &n, &m);
  for (int i = 1, j; i <= n; i++) {
    scanf("%d", &j);
    T.modify(1, 1, n, i, i, j);
  }
  while (m--) {
    scanf("%s%d%d%d", op, &L, &R, &x);
    if (op[0] == '=')
      T.modify(1, 1, n, L, R, x);
    else
      printf("%d\n", T.query(1, 1, n, L, R, x));
  }
  return 0;
}
