#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const long long LIM = 1e18;
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const double PI = atan(1.0) * 4;
const int mod = 1e9 + 7;
int n, m, a[N + 10];
long long c[6][6], fac[N + 10][6], sum[N + 10][6], s[N + 10][6];
long long tree[(N + 10) << 2][6], lazy[(N + 10) << 2];
void pushup(int x) {
  for (int i = 0; i < 6; i++)
    tree[x][i] = (tree[x << 1][i] + tree[x << 1 | 1][i]) % mod;
}
void update(int x, int l, int r, int L, int R, int v);
void pushdown(int x, int l, int r) {
  if (lazy[x] == -1) return;
  int mid = (l + r) / 2;
  update(x << 1, l, mid, l, mid, lazy[x]);
  update(x << 1 | 1, mid + 1, r, mid + 1, r, lazy[x]);
  lazy[x] = -1;
}
void build(int x, int l, int r) {
  lazy[x] = -1;
  if (l == r) {
    for (int i = 0; i < 6; i++) tree[x][i] = 1LL * a[l] * fac[l][i] % mod;
    return;
  }
  int mid = (l + r) / 2;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
void init() {
  for (int i = 0; i < 6; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]);
  }
  for (int i = 1; i <= n; i++) {
    fac[i][0] = s[i][0] = 1;
    sum[i][0] = i;
  }
  for (int i = 1; i < 6; i++)
    for (int j = 1; j <= n; j++) {
      fac[j][i] = (fac[j][i - 1] * j) % mod;
      sum[j][i] = (sum[j - 1][i] + fac[j][i]) % mod;
      s[j][i] = (s[j][i - 1] * (1 - j) % mod + mod) % mod;
    }
  build(1, 1, n);
}
void update(int x, int l, int r, int L, int R, int v) {
  if (L == l && r == R) {
    lazy[x] = v;
    for (int i = 0; i < 6; i++) {
      int tmp = ((sum[r][i] - sum[l - 1][i]) % mod + mod) % mod;
      tree[x][i] = 1LL * tmp * v % mod;
    }
    return;
  }
  pushdown(x, l, r);
  int mid = (l + r) / 2;
  if (R <= mid)
    update(x << 1, l, mid, L, R, v);
  else if (L > mid)
    update(x << 1 | 1, mid + 1, r, L, R, v);
  else
    update(x << 1, l, mid, L, mid, v),
        update(x << 1 | 1, mid + 1, r, mid + 1, R, v);
  pushup(x);
}
int query(int x, int l, int r, int L, int R, int idx) {
  if (L == l && r == R) return tree[x][idx];
  pushdown(x, l, r);
  int mid = (l + r) / 2, res = 0;
  if (R <= mid)
    res = query(x << 1, l, mid, L, R, idx);
  else if (L > mid)
    res = query(x << 1 | 1, mid + 1, r, L, R, idx);
  else
    res = (query(x << 1, l, mid, L, mid, idx) +
           query(x << 1 | 1, mid + 1, r, mid + 1, R, idx)) %
          mod;
  return res;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  init();
  while (m--) {
    char opt[2];
    int l, r, x;
    cin >> opt >> l >> r >> x;
    if (opt[0] == '=')
      update(1, 1, n, l, r, x);
    else {
      int ans = 0;
      for (int i = 0; i <= x; i++) {
        int valu = query(1, 1, n, l, r, i);
        ans = ((1LL * valu * c[x][i] % mod * s[l][x - i] % mod + ans) % mod +
               mod) %
              mod;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
