#include <bits/stdc++.h>
template <class Num>
void read(Num &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c - '0');
  x *= flag;
}
template <class Num>
void write(Num x) {
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  static char s[20];
  int sl = 0;
  while (x) s[sl++] = x % 10 + '0', x /= 10;
  while (sl) putchar(s[--sl]);
}
const int maxn = 1e5 + 20, Mod = 1e9 + 7, maxk = 10;
int n, m, a[maxn];
long long cnt[maxk][maxn << 2], tag[maxn << 2];
long long sum[maxk][maxn];
void pushdown(int x, int l, int r) {
  if (tag[x] == -1) return;
  int mid = (l + r) >> 1;
  for (int i = 0; i <= 5; i++) {
    cnt[i][((x) << 1)] =
        (sum[i][mid] - sum[i][l - 1] + Mod) % Mod * tag[x] % Mod;
    cnt[i][((x) << 1 | 1)] =
        (sum[i][r] - sum[i][mid] + Mod) % Mod * tag[x] % Mod;
  }
  tag[((x) << 1)] = tag[x], tag[((x) << 1 | 1)] = tag[x], tag[x] = -1;
}
void update(int x) {
  for (int i = 0; i <= 5; i++)
    cnt[i][x] = (cnt[i][((x) << 1)] + cnt[i][((x) << 1 | 1)]) % Mod;
}
void build(int l, int r, int s) {
  if (l == r) {
    for (int i = 0; i <= 5; i++)
      cnt[i][s] = (sum[i][r] - sum[i][l - 1] + Mod) % Mod * a[l] % Mod;
  } else {
    int mid = (l + r) >> 1;
    build(l, mid, ((s) << 1)), build(mid + 1, r, ((s) << 1 | 1));
    tag[s] = -1, update(s);
  }
}
void change(int l, int r, int v, int ll, int rr, int s) {
  if (ll == l && rr == r) {
    for (int i = 0; i <= 5; i++)
      cnt[i][s] = (sum[i][r] - sum[i][l - 1] + Mod) % Mod * v % Mod;
    tag[s] = v;
  } else {
    pushdown(s, ll, rr);
    int mid = (ll + rr) >> 1;
    if (r <= mid)
      change(l, r, v, ll, mid, ((s) << 1));
    else if (l > mid)
      change(l, r, v, mid + 1, rr, ((s) << 1 | 1));
    else {
      change(l, mid, v, ll, mid, ((s) << 1));
      change(mid + 1, r, v, mid + 1, rr, ((s) << 1 | 1));
    }
    update(s);
  }
}
void query(int l, int r, long long *ret, int ll, int rr, int s) {
  if (ll == l && rr == r) {
    for (int i = 0; i <= 5; i++) ret[i] += cnt[i][s], ret[i] %= Mod;
  } else {
    pushdown(s, ll, rr);
    int mid = (ll + rr) >> 1;
    if (r <= mid)
      query(l, r, ret, ll, mid, ((s) << 1));
    else if (l > mid)
      query(l, r, ret, mid + 1, rr, ((s) << 1 | 1));
    else {
      query(l, mid, ret, ll, mid, ((s) << 1));
      query(mid + 1, r, ret, mid + 1, rr, ((s) << 1 | 1));
    }
    update(s);
  }
}
long long power(int x, int y) {
  long long r = 1;
  while (y--) r = (r * x) % Mod;
  return r;
}
int choice(int y, int x) {
  int r = 1;
  for (int i = x + 1; i <= y; i++) r *= i;
  for (int i = 2; i <= y - x; i++) r /= i;
  return r;
}
void solve() {
  char ch[3];
  int x, y, k;
  scanf("%s", ch);
  read(x), read(y), read(k);
  if (ch[0] == '?') {
    long long g[maxk] = {0}, ans = 0;
    query(x, y, g, 1, n, 1);
    for (int i = 0; i <= k; i++)
      ans += g[i] * power(Mod - x + 1, k - i) % Mod * choice(k, i) % Mod;
    write(ans % Mod), puts("");
  } else
    change(x, y, k, 1, n, 1);
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int t = 0; t <= 5; t++)
    for (int i = 1; i <= n; i++)
      sum[t][i] = (sum[t][i - 1] + power(i, t)) % Mod;
  build(1, n, 1);
  for (int i = 1; i <= m; i++) solve();
  return 0;
}
