#include <bits/stdc++.h>
using namespace std;
int n, m;
int C[10][10], Sum[100010][10], tong[10];
int Key[5 * 100010][10], dw[5 * 100010];
void Cover(int node, int l, int r, int gt) {
  dw[node] = gt;
  for (int i = 0; i <= 5; i++)
    Key[node][i] = (1ll * Sum[r][i] - Sum[l - 1][i]) * gt % 1000000007;
}
void Down(int node, int l, int r) {
  if (l < r && dw[node] >= 0) {
    int mid = (l + r) >> 1;
    Cover(node * 2, l, mid, dw[node]);
    Cover(node * 2 + 1, mid + 1, r, dw[node]);
    dw[node] = -1;
  }
}
void Gan(int node, int dau, int cuoi, int l, int r, int gt) {
  Down(node, dau, cuoi);
  if (dau >= l && cuoi <= r) {
    Cover(node, dau, cuoi, gt);
    return;
  }
  int mid = (dau + cuoi) / 2;
  if (mid >= l) Gan(node * 2, dau, mid, l, r, gt);
  if (mid < r) Gan(node * 2 + 1, mid + 1, cuoi, l, r, gt);
  for (int i = 0; i <= 5; i++)
    Key[node][i] = (1ll * Key[node * 2][i] + Key[node * 2 + 1][i]) % 1000000007;
}
void nhap() {
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 1; i <= 4 * 100010; i++)
    for (int j = 0; j <= 5; j++) Key[i][j] = 0;
}
void chuanbi() {
  for (int i = 0; i <= 5; i++) C[i][i] = C[i][0] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= i - 1; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  for (int i = 1; i <= n; i++) Sum[i][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 5; j++)
      Sum[i][j] = (1ll * Sum[i][j - 1] * i) % 1000000007;
    for (int j = 0; j <= 5; j++)
      Sum[i][j] = (Sum[i - 1][j] + Sum[i][j]) % 1000000007;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    Gan(1, 1, n, i, i, x);
  }
}
void Tinh(int node, int dau, int cuoi, int l, int r) {
  Down(node, dau, cuoi);
  if (l <= dau && cuoi <= r) {
    for (int i = 0; i <= 5; i++)
      tong[i] = (1ll * tong[i] + Key[node][i]) % 1000000007;
  } else {
    int mid = (cuoi + dau) / 2;
    if (mid >= l) Tinh(node * 2, dau, mid, l, r);
    if (mid < r) Tinh(node * 2 + 1, mid + 1, cuoi, l, r);
  }
}
void xuli() {
  for (int i = 1; i <= m; i++) {
    char yeucau;
    int l, r, k;
    cin >> yeucau;
    scanf("%d", &l), scanf("%d", &r), scanf("%d", &k);
    if (yeucau == '=')
      Gan(1, 1, n, l, r, k);
    else {
      memset(tong, 0, sizeof(tong));
      Tinh(1, 1, n, l, r);
      int kq = 0, t = 1;
      for (int i = k; i >= 0; i--) {
        kq = (1ll * kq + 1ll * tong[i] * C[k][i] % 1000000007 * t) % 1000000007;
        t = 1ll * t * (1 - l) % 1000000007;
      }
      printf("%d\n", (kq + 1000000007) % 1000000007);
    }
  }
}
void inkq() {}
int main() {
  for (int i = 1; i <= 5 * 100010 - 10; i++) dw[i] = -1;
  nhap();
  chuanbi();
  xuli();
  inkq();
  return 0;
}
