#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
struct node {
  int l, r, flag, sum[6];
} t[MAXN << 2];
int cnt[6];
int fact[6][MAXN];
int a[MAXN], n, m;
void change(int k, int val) {
  int l = t[k].l, r = t[k].r;
  for (int i = 0; i <= 5; i++) {
    t[k].sum[i] = (long long)(fact[i][r] - fact[i][l - 1]) * val % mod;
    t[k].sum[i] = (t[k].sum[i] % mod + mod) % mod;
  }
  t[k].flag = val;
}
void push_down(int k) {
  if (t[k].flag != -1) {
    change(k << 1, t[k].flag);
    change(k << 1 | 1, t[k].flag);
    t[k].flag = -1;
  }
}
void push_up(int k) {
  for (int i = 0; i <= 5; i++) {
    t[k].sum[i] = (t[k << 1].sum[i] + t[k << 1 | 1].sum[i]) % mod;
  }
}
void build(int l, int r, int k) {
  t[k].l = l;
  t[k].r = r;
  t[k].flag = -1;
  if (l == r) {
    change(k, a[l]);
    return;
  }
  int mid = t[k].l + t[k].r >> 1;
  build(l, mid, k << 1);
  build(mid + 1, r, k << 1 | 1);
  push_up(k);
}
void update(int l, int r, int val, int k) {
  if (l <= t[k].l && t[k].r <= r) {
    change(k, val);
    return;
  }
  push_down(k);
  int mid = t[k].l + t[k].r >> 1;
  if (l <= mid) update(l, r, val, k << 1);
  if (r > mid) update(l, r, val, k << 1 | 1);
  push_up(k);
}
void query(int l, int r, int k) {
  if (l <= t[k].l && t[k].r <= r) {
    for (int i = 0; i <= 5; i++) {
      cnt[i] += t[k].sum[i];
      if (cnt[i] >= mod) cnt[i] -= mod;
    }
    return;
  }
  push_down(k);
  int mid = t[k].l + t[k].r >> 1;
  if (l <= mid) query(l, r, k << 1);
  if (r > mid) query(l, r, k << 1 | 1);
}
char op[5];
int x, y, z;
int c[6][6];
int power[6];
int main() {
  scanf("%d%d", &n, &m);
  c[0][0] = 1;
  c[1][0] = c[1][1] = 1;
  for (int i = 2; i <= 5; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int k = 0; k <= 5; k++) {
    fact[k][0] = 0;
    for (int i = 1; i <= n; i++) {
      int te = 1;
      for (int j = 1; j <= k; j++) te = (long long)te * i % mod;
      fact[k][i] = fact[k][i - 1] + te;
      if (fact[k][i] >= mod) fact[k][i] -= mod;
    }
  }
  build(1, n, 1);
  while (m--) {
    scanf("%s", op);
    scanf("%d%d%d", &x, &y, &z);
    if (op[0] != '?') {
      update(x, y, z, 1);
    } else {
      for (int i = 0; i <= z; i++) cnt[i] = 0;
      power[0] = 1;
      for (int i = 1; i <= z; i++)
        power[i] = (long long)power[i - 1] * (1 - x) % mod;
      query(x, y, 1);
      long long ans = 0;
      for (int x = 0; x <= z; x++) {
        ans = ans + (long long)power[x] * cnt[z - x] % mod * c[z][x] % mod;
        ans = (ans % mod + mod) % mod;
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
