#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
const int MAXK = 5;
const int MOD = 1e9 + 7;
const int UNSET = -1;
const int sign[] = {1, -1};
int a[MAXN + 1];
int sum[MAXK + 1][MAXN + 1];
int nCr[MAXK + 1][MAXK + 1];
int tree[MAXK + 1][4 * MAXN];
int lazy[4 * MAXN];
int tmp, x;
long long ans;
char c;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int binpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (1LL * ans * x) % MOD;
    x = (1LL * x * x) % MOD;
    y >>= 1;
  }
  return ans;
}
void pushup(int v, int l, int r) {
  for (int i = 0; i <= MAXK; i++) tree[i][v] = (tree[i][l] + tree[i][r]) % MOD;
}
void pushdown(int v, int l, int r) {
  if (lazy[v] == UNSET) return;
  for (int i = 0; i <= MAXK; i++)
    tree[i][v] =
        (1LL * (sum[i][r] - sum[i][l - 1] + MOD) % MOD * lazy[v]) % MOD;
  if (l != r) {
    int L = (v << 1), R = (L | 1);
    lazy[L] = lazy[R] = lazy[v];
  }
  lazy[v] = UNSET;
}
void build(int v, int l, int r) {
  lazy[v] = UNSET;
  if (l == r) {
    for (int i = 0; i <= MAXK; i++)
      tree[i][v] = (1LL * a[l] * binpow(l, i)) % MOD;
  } else {
    int mid = (l + r) >> 1;
    int L = (v << 1), R = (L | 1);
    build(L, l, mid);
    build(R, mid + 1, r);
    pushup(v, L, R);
  }
}
void update(int v, int tl, int tr, int l, int r, int val) {
  pushdown(v, tl, tr);
  if (l > tr or r < tl) return;
  if (l <= tl and r >= tr) {
    lazy[v] = val;
    pushdown(v, tl, tr);
  } else {
    int mid = (tl + tr) >> 1;
    int L = (v << 1), R = (L | 1);
    update(L, tl, mid, l, r, val);
    update(R, mid + 1, tr, l, r, val);
    pushup(v, L, R);
  }
}
int query(int v, int tl, int tr, int l, int r, int k) {
  pushdown(v, tl, tr);
  if (l > tr or r < tl) return 0;
  if (l <= tl and r >= tr) return tree[k][v];
  int mid = (tl + tr) >> 1;
  int L = (v << 1), R = (L | 1);
  return (query(L, tl, mid, l, r, k) + query(R, mid + 1, tr, l, r, k)) % MOD;
}
void prepare() {
  for (int i = 0; i <= MAXK; i++) {
    for (int j = 1; j <= MAXN; j++)
      sum[i][j] = (sum[i][j - 1] + binpow(j, i)) % MOD;
  }
  for (int i = 0; i <= MAXK; i++) {
    nCr[i][0] = 1;
  }
  for (int i = 1; i <= MAXK; i++) {
    for (int j = 1; j <= MAXK; j++)
      nCr[i][j] = nCr[i - 1][j] + nCr[i - 1][j - 1];
  }
}
int main() {
  fast_io();
  prepare();
  int n, q, l, r;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  build(1, 1, n);
  while (q--) {
    cin >> c >> l >> r >> x;
    if (c == '=')
      update(1, 1, n, l, r, x);
    else {
      ans = 0;
      for (int j = 0; j <= x; j++) {
        tmp = (1LL * (1LL * query(1, 1, n, l, r, j) * binpow(l - 1, x - j)) %
               MOD * nCr[x][j]) %
              MOD;
        tmp *= sign[(x - j) & 1];
        ans = (ans + tmp + MOD) % MOD;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
