#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005];
struct node {
  int l, r;
  int data;
  long long int sum;
} tree[6][100005 << 2];
long long f[100005][6], g[100005][6];
void build(int P, int p, int l, int r) {
  tree[P][p].l = l;
  tree[P][p].r = r;
  if (l == r) {
    tree[P][p].data = a[l];
    tree[P][p].sum = (g[l][P] * a[l]) % 1000000007;
    return;
  }
  int mid = (l + r) >> 1;
  build(P, p << 1, l, mid);
  build(P, p << 1 | 1, mid + 1, r);
  tree[P][p].sum = (tree[P][p << 1].sum + tree[P][p << 1 | 1].sum) % 1000000007;
  if (tree[P][p << 1].data == tree[P][p << 1 | 1].data)
    tree[P][p].data = tree[P][p << 1].data;
  else
    tree[P][p].data = -1;
}
void updata(int P, int p, int l, int r) {
  tree[P][p << 1].data = tree[P][p << 1 | 1].data = tree[P][p].data;
  int mid = (l + r) >> 1;
  tree[P][p << 1].sum =
      (f[mid][P] - f[l - 1][P]) * tree[P][p].data % 1000000007;
  tree[P][p << 1 | 1].sum =
      (f[r][P] - f[mid][P]) * tree[P][p].data % 1000000007;
}
void insert(int P, int p, int l, int r, int data) {
  if (tree[P][p].l == l && tree[P][p].r == r) {
    tree[P][p].data = data;
    tree[P][p].sum = (f[r][P] - f[l - 1][P]) * data % 1000000007;
    return;
  }
  if (tree[P][p].data >= 0) {
    updata(P, p, tree[P][p].l, tree[P][p].r);
    tree[P][p].data = -1;
  }
  int mid = (tree[P][p].l + tree[P][p].r) >> 1;
  if (mid >= r)
    insert(P, p << 1, l, r, data);
  else if (mid < l)
    insert(P, p << 1 | 1, l, r, data);
  else {
    insert(P, p << 1, l, mid, data);
    insert(P, p << 1 | 1, mid + 1, r, data);
  }
  tree[P][p].sum = (tree[P][p << 1].sum + tree[P][p << 1 | 1].sum) % 1000000007;
}
long long cal(int P, int p, int l, int r) {
  if (tree[P][p].l == l && tree[P][p].r == r) return tree[P][p].sum;
  if (tree[P][p].data >= 0) updata(P, p, tree[P][p].l, tree[P][p].r);
  int mid = (tree[P][p].l + tree[P][p].r) >> 1;
  if (mid >= r)
    return cal(P, p << 1, l, r);
  else if (mid < l)
    return cal(P, p << 1 | 1, l, r);
  else {
    long long tmp1 = cal(P, p << 1, l, mid);
    long long tmp2 = cal(P, p << 1 | 1, mid + 1, r);
    return (tmp1 + tmp2) % 1000000007;
  }
}
int c[6][6];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int j = 0; j <= 100000; j++) {
    g[j][0] = 1;
    for (int i = 1; i <= 5; i++) g[j][i] = g[j][i - 1] * j % 1000000007;
  }
  for (int i = 0; i <= 5; i++)
    for (int j = 1; j <= 100000; j++)
      f[j][i] = (f[j - 1][i] + g[j][i]) % 1000000007;
  for (int i = 0; i <= 5; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  for (int i = 0; i <= 5; i++) build(i, 1, 1, n);
  char st[5];
  int l, r, k;
  while (m--) {
    scanf("%s%d%d%d", st, &l, &r, &k);
    if (st[0] == '=') {
      for (int i = 0; i <= 5; i++) insert(i, 1, l, r, k);
    } else {
      long long ans = 0, t = 1;
      for (int i = k; i >= 0; i--) {
        ans = (ans + cal(i, 1, l, r) * t % 1000000007 * c[k][i] % 1000000007) %
              1000000007;
        t = t * (1 - l) % 1000000007;
      }
      if (ans < 0) ans += 1000000007;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
