#include <bits/stdc++.h>
using namespace std;
const int P = 1000000007;
int add(int a, int b) { return a + b >= P ? a + b - P : a + b; }
int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = res * (long long)a % P;
    a = (long long)a * a % P;
    b >>= 1;
  }
  return res;
}
int inv(int x) { return qpow(x, P - 2); }
const int N = 100010;
int n, m, a[N];
int sum[N << 2][6], tag[N << 2], pwk[N][6];
void up(int p) {
  for (int i = 0; i <= 5; ++i)
    sum[p][i] = add(sum[p << 1][i], sum[p << 1 | 1][i]);
}
void change(int p, int v, int l, int r) {
  tag[p] = v;
  for (int i = 0; i <= 5; ++i)
    sum[p][i] = (long long)v * (pwk[r][i] - pwk[l - 1][i] + P) % P;
}
void push(int p, int l, int r) {
  if (tag[p] != -1) {
    int mid = (l + r) >> 1;
    change(p << 1, tag[p], l, mid);
    change(p << 1 | 1, tag[p], mid + 1, r);
    tag[p] = -1;
  }
}
void build(int p, int l, int r) {
  tag[p] = -1;
  if (l == r) {
    for (int i = 0; i <= 5; ++i) sum[p][i] = (long long)a[l] * qpow(l, i) % P;
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  up(p);
}
void update(int p, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    change(p, v, l, r);
    return;
  }
  push(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(p << 1, l, mid, L, R, v);
  if (R > mid) update(p << 1 | 1, mid + 1, r, L, R, v);
  up(p);
}
int qry(int p, int l, int r, int L, int R, int t) {
  if (L <= l && r <= R) return sum[p][t];
  push(p, l, r);
  int mid = (l + r) >> 1, res = 0;
  if (L <= mid) res = add(res, qry(p << 1, l, mid, L, R, t));
  if (R > mid) res = add(res, qry(p << 1 | 1, mid + 1, r, L, R, t));
  up(p);
  return res;
}
int c[10][10];
int main() {
  cout << fixed;
  scanf("%d%d", &n, &m);
  for (int j = 0; j <= 5; ++j) pwk[0][j] = qpow(0, j);
  c[0][0] = 1;
  for (int i = 1; i <= 5; ++i) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; ++j) c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= 5; ++j) pwk[i][j] = add(pwk[i - 1][j], qpow(i, j));
  build(1, 1, n);
  for (int q = 1; q <= m; ++q) {
    char op[3];
    int l, r, k;
    scanf("%s%d%d%d", op, &l, &r, &k);
    if (op[0] == '=')
      update(1, 1, n, l, r, k);
    else if (op[0] == '?') {
      int res = 0;
      for (int j = 0; j <= k; ++j) {
        int ans = (long long)c[k][j] * qpow((1 - l + P) % P, k - j) % P *
                  qry(1, 1, n, l, r, j) % P;
        res = add(res, ans);
      }
      printf("%d\n", res);
    }
  }
  return 0;
}
