#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
const int T = 1e9 + 7;
bool flag[maxn * 4];
long long ch[6][maxn * 4], sum[6][maxn * 4];
int a[maxn], val[maxn * 4], c[6][6];
void build(int l, int r, int cur) {
  if (l == r) {
    long long buf = 1;
    for (int i = 0; i <= 5; i++) {
      sum[i][cur] = buf;
      ch[i][cur] = buf * a[l] % T;
      buf *= l;
      buf %= T;
    }
    return;
  }
  int lc = cur << 1, rc = lc | 1, mid = (l + r) >> 1;
  build(l, mid, lc);
  build(mid + 1, r, rc);
  for (int i = 0; i <= 5; i++) {
    ch[i][cur] = (ch[i][lc] + ch[i][rc]) % T;
    sum[i][cur] = (sum[i][lc] + sum[i][rc]) % T;
  }
  return;
}
void Push_down(int cur) {
  int lc = cur << 1, rc = lc | 1;
  flag[cur] = 0;
  flag[lc] = flag[rc] = 1;
  val[lc] = val[rc] = val[cur];
  for (int i = 0; i <= 5; i++) {
    ch[i][lc] = sum[i][lc] * val[lc] % T;
    ch[i][rc] = sum[i][rc] * val[rc] % T;
    ch[i][cur] = (ch[i][lc] + ch[i][rc]) % T;
  }
  return;
}
void update(int l, int r, int cur, int x, int y, int v) {
  if (l > y || r < x) return;
  if (x <= l && r <= y) {
    flag[cur] = 1;
    val[cur] = v;
    for (int i = 0; i <= 5; i++) ch[i][cur] = sum[i][cur] * v % T;
    return;
  }
  if (flag[cur]) Push_down(cur);
  int lc = cur << 1, rc = lc | 1, mid = (l + r) >> 1;
  update(l, mid, lc, x, y, v);
  update(mid + 1, r, rc, x, y, v);
  for (int i = 0; i <= 5; i++) ch[i][cur] = (ch[i][lc] + ch[i][rc]) % T;
  return;
}
int query(int i, int l, int r, int cur, int x, int y) {
  if (l > y || r < x) return 0;
  if (x <= l && r <= y) return ch[i][cur];
  if (flag[cur]) Push_down(cur);
  int lc = cur << 1, rc = lc | 1, mid = (l + r) >> 1;
  return (query(i, l, mid, lc, x, y) + query(i, mid + 1, r, rc, x, y)) % T;
}
int main() {
  for (int i = 0; i <= 5; i++) c[i][0] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, n, 1);
  getchar();
  for (int i = 1; i <= m; i++) {
    char op = getchar();
    if (op == '=') {
      int l, r, v;
      scanf("%d%d%d", &l, &r, &v);
      update(1, n, 1, l, r, v);
    } else {
      int l, r, k;
      int ans = 0;
      long long buf = 1;
      scanf("%d%d%d", &l, &r, &k);
      for (int j = k; j >= 0; j--) {
        ans += (query(j, 1, n, 1, l, r) * buf % T) * c[k][j] % T;
        ans %= T;
        buf *= (1 - l);
        buf %= T;
      }
      if (ans < 0) ans += T;
      printf("%d\n", ans);
    }
    getchar();
  }
  return 0;
}
