#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
const int MOD = 1000000007;
struct data {
  int l, r, mid, mark;
  long long sum[6];
};
int n, m, a[maxn];
data tr[maxn * 5];
long long G[maxn][6], C[6][6], ans[6];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("\n");
  C[0][0] = 1;
  for (int i = 1; i < 6; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
  long long tmp;
  for (int i = 1; i <= n; ++i) {
    tmp = 1;
    for (int j = 0; j < 6; ++j) {
      G[i][j] = (G[i - 1][j] + tmp) % MOD;
      tmp = tmp * i % MOD;
    }
  }
}
void change(int id, int l, int r, int z) {
  for (int i = 0; i < 6; ++i)
    tr[id].sum[i] = ((G[r][i] - G[l - 1][i]) % MOD + MOD) % MOD * z % MOD;
}
void pushdown(int id) {
  if (tr[id].mark != -1) {
    tr[id * 2].mark = tr[id * 2 + 1].mark = tr[id].mark;
    change(id * 2, tr[id * 2].l, tr[id * 2].r, tr[id].mark);
    change(id * 2 + 1, tr[id * 2 + 1].l, tr[id * 2 + 1].r, tr[id].mark);
    tr[id].mark = -1;
  }
}
void pushup(int id) {
  for (int i = 0; i < 6; ++i)
    tr[id].sum[i] = (tr[id * 2].sum[i] + tr[id * 2 + 1].sum[i]) % MOD;
}
void build(int id, int l, int r) {
  int mid = (l + r) / 2;
  tr[id].l = l;
  tr[id].r = r;
  tr[id].mid = mid;
  tr[id].mark = -1;
  if (l == r) {
    change(id, l, r, a[l]);
    return;
  }
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  pushup(id);
}
void query(int id, int l, int r, long long dat[6]) {
  if ((tr[id].l == l) && (tr[id].r == r)) {
    for (int i = 0; i < 6; ++i) dat[i] = tr[id].sum[i];
    return;
  }
  pushdown(id);
  if (r <= tr[id].mid)
    query(id * 2, l, r, dat);
  else if (l > tr[id].mid)
    query(id * 2 + 1, l, r, dat);
  else {
    long long t1[6], t2[6];
    query(id * 2, l, tr[id].mid, t1);
    query(id * 2 + 1, tr[id].mid + 1, r, t2);
    for (int i = 0; i < 6; ++i) dat[i] = (t1[i] + t2[i]) % MOD;
  }
  pushup(id);
}
void ins(int id, int l, int r, int z) {
  if ((tr[id].l == l) && (tr[id].r == r)) {
    tr[id].mark = z;
    change(id, l, r, z);
    return;
  }
  pushdown(id);
  if (r <= tr[id].mid)
    ins(id * 2, l, r, z);
  else if (l > tr[id].mid)
    ins(id * 2 + 1, l, r, z);
  else {
    ins(id * 2, l, tr[id].mid, z);
    ins(id * 2 + 1, tr[id].mid + 1, r, z);
  }
  pushup(id);
}
void work() {
  int x, y, z;
  long long tmp[6], s;
  char ch;
  for (int i = 1; i <= m; ++i) {
    scanf("%c%d%d%d\n", &ch, &x, &y, &z);
    if (ch == '?') {
      query(1, x, y, tmp);
      for (int k = 0; k < 6; ++k) {
        ans[k] = tmp[k];
        s = 1;
        for (int i = 1; i <= k; ++i) {
          s = s * (x - 1) % MOD;
          ans[k] =
              ((ans[k] - C[k][i] * s % MOD * ans[k - i]) % MOD + MOD) % MOD;
        }
      }
      printf("%I64d\n", ans[z]);
    } else
      ins(1, x, y, z);
  }
}
int main() {
  init();
  build(1, 1, n);
  work();
}
