#include <bits/stdc++.h>
using namespace std;
struct node {
  long long a[6];
};
long long sum[6][100005 << 2], col[100005 << 2], data[6][100005], C[6][6],
    POW[100005][6];
node ADD(node a, node b) {
  int i;
  for (i = 0; i < 6; i++) a.a[i] = (a.a[i] + b.a[i]) % 1000000007;
  return a;
}
void PreWork() {
  int i, j;
  long long x;
  memset(data, 0, sizeof(data));
  POW[0][0] = 1;
  for (i = 1; i <= 100000; i++) {
    x = 1;
    for (j = 0; j < 6; j++)
      POW[i][j] = x, data[j][i] = (data[j][i - 1] + x) % 1000000007,
      x = (x * i) % 1000000007;
  }
  for (i = 0; i < 6; i++) C[i][0] = C[i][i] = 1;
  for (i = 1; i < 6; i++)
    for (j = 1; j < 6; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  return;
}
void PushDown(int l, int r, int now) {
  int i, mid = (l + r) / 2;
  long long x;
  if (col[now] < 0) return;
  col[now << 1] = col[(now << 1) | 1] = col[now];
  for (i = 0; i < 6; i++) {
    x = data[i][mid] - data[i][l - 1];
    if (x < 0) x = 1000000007 + x;
    sum[i][now << 1] = (col[now] * x) % 1000000007;
    x = data[i][r] - data[i][mid];
    if (x < 0) x = 1000000007 + x;
    sum[i][(now << 1) | 1] =
        (col[now] * (data[i][r] - data[i][mid])) % 1000000007;
  }
  col[now] = -1;
  return;
}
void update(int L, int R, int c, int l, int r, int now) {
  int i;
  long long x;
  if (L <= l && R >= r) {
    col[now] = c;
    for (i = 0; i < 6; i++) {
      x = data[i][r] - data[i][l - 1];
      if (x < 0) x = 1000000007 + x;
      sum[i][now] = (c * x) % 1000000007;
    }
    return;
  }
  PushDown(l, r, now);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, c, l, mid, now << 1);
  if (mid < R) update(L, R, c, mid + 1, r, (now << 1) | 1);
  for (i = 0; i < 6; i++)
    sum[i][now] = (sum[i][now << 1] + sum[i][(now << 1) | 1]) % 1000000007;
  return;
}
node query(int L, int R, int l, int r, int now) {
  node h, p;
  if (L <= l && R >= r) {
    for (int i = 0; i < 6; i++) h.a[i] = sum[i][now];
    return h;
  }
  PushDown(l, r, now);
  int mid = (l + r) >> 1;
  memset(h.a, 0, sizeof(h.a));
  if (L <= mid) h = ADD(h, query(L, R, l, mid, now << 1));
  if (mid < R) h = ADD(h, query(L, R, mid + 1, r, (now << 1) | 1));
  return h;
}
long long getans(node h, long long L, int k) {
  int i;
  long long t, ans = 0;
  for (i = 0; i <= k; i++) {
    t = (C[k][i] * h.a[i]) % 1000000007;
    t = (t * POW[L - 1][k - i]) % 1000000007;
    if ((k - i) % 2) t = -t;
    ans = (ans + t) % 1000000007;
  }
  return (ans + 1000000007) % 1000000007;
}
int main() {
  int i, n, m, x, y, z;
  char c;
  PreWork();
  while (~scanf("%d%d", &n, &m)) {
    memset(sum, 0, sizeof(sum));
    memset(col, -1, sizeof(col));
    for (i = 1; i <= n; i++) {
      scanf("%d", &x);
      update(i, i, x, 1, n, 1);
    }
    while (m--) {
      do {
        c = getchar();
      } while (c != '=' && c != '?');
      scanf("%d%d%d", &x, &y, &z);
      if (c == '?')
        printf("%I64d\n", getans(query(x, y, 1, n, 1), x, z));
      else
        update(x, y, z, 1, n, 1);
    }
  }
  return 0;
}
