#include <bits/stdc++.h>
const int N = 1e5;
const int P = 1e9 + 7;
struct Node {
  int sum[6], tag;
};
Node t[(N << 2) + 10];
int a[N + 10], n, m, s[N + 10][6], C[6][6];
inline int add(int a, int b) { return a + b >= P ? a + b - P : a + b; }
inline int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1LL * res * a % P;
    a = 1LL * a * a % P;
    b >>= 1;
  }
  return res;
}
inline void pushUp(int i) {
  for (int j = 0; j < 6; j++)
    t[i].sum[j] = add(t[(i << 1)].sum[j], t[(i << 1 | 1)].sum[j]);
}
inline void pushTag(int i, int l, int r, int tag) {
  t[i].tag = tag;
  for (int j = 0; j < 6; j++)
    t[i].sum[j] = 1LL * tag * (s[r][j] - s[l - 1][j] + P) % P;
}
inline void pushDown(int i, int l, int r) {
  if (t[i].tag != -1) {
    int mid = (l + r) >> 1;
    pushTag((i << 1), l, mid, t[i].tag);
    pushTag((i << 1 | 1), mid + 1, r, t[i].tag);
    t[i].tag = -1;
  }
}
void build(int i, int l, int r) {
  t[i].tag = -1;
  if (l == r) {
    for (int j = 0; j < 6; j++) t[i].sum[j] = 1LL * a[l] * qpow(l, j) % P;
    return;
  }
  int mid = (l + r) >> 1;
  build((i << 1), l, mid);
  build((i << 1 | 1), mid + 1, r);
  pushUp(i);
}
void modify(int i, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) return pushTag(i, l, r, v);
  int mid = (l + r) >> 1;
  pushDown(i, l, r);
  if (ql <= mid) modify((i << 1), l, mid, ql, qr, v);
  if (qr > mid) modify((i << 1 | 1), mid + 1, r, ql, qr, v);
  pushUp(i);
}
int query(int i, int l, int r, int ql, int qr, int k) {
  if (ql <= l && r <= qr) return t[i].sum[k];
  int mid = (l + r) >> 1;
  pushDown(i, l, r);
  int res = 0;
  if (ql <= mid) res = add(res, query((i << 1), l, mid, ql, qr, k));
  if (qr > mid) res = add(res, query((i << 1 | 1), mid + 1, r, ql, qr, k));
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int j = 0; j <= 5; j++) s[0][j] = qpow(0, j);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 6; j++) s[i][j] = add(s[i - 1][j], qpow(i, 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]);
  }
  build(1, 1, n);
  while (m--) {
    char opt[5];
    int l, r, v;
    scanf("%s%d%d%d", opt, &l, &r, &v);
    if (opt[0] == '=')
      modify(1, 1, n, l, r, v);
    else {
      int ans = 0;
      for (int j = 0; j <= v; j++) {
        int res = 1LL * C[v][j] * qpow((1 - l + P) % P, v - j) % P *
                  query(1, 1, n, l, r, j) % P;
        ans = add(ans, res);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
