#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
const int hinf = 0x3f3f3f3f;
const long long mod = 1000000007;
struct node {
  int l, r;
  long long sum[6], add;
} sgt[100010 << 2];
int dat[100010];
int n, m;
int cm[6][6];
long long p[100010][6];
long long s[100010][6];
void up(int root) {
  for (int i = 0; i < 6; i++)
    sgt[root].sum[i] = sgt[root << 1].sum[i] + sgt[root << 1 | 1].sum[i];
}
void down(int root) {
  if (sgt[root].add == -1) return;
  for (int i = 0; i < 6; i++) {
    sgt[root << 1].sum[i] =
        (sgt[root].add *
             ((s[sgt[root << 1].r][i] - s[sgt[root << 1].l - 1][i] + mod) %
              mod) +
         mod) %
        mod;
    sgt[root << 1 | 1].sum[i] =
        (sgt[root].add * ((s[sgt[root << 1 | 1].r][i] -
                           s[sgt[root << 1 | 1].l - 1][i] + mod) %
                          mod) +
         mod) %
        mod;
  }
  sgt[root << 1].add = sgt[root].add;
  sgt[root << 1 | 1].add = sgt[root].add;
  sgt[root].add = -1;
}
void build(int l, int r, int root) {
  sgt[root].l = l;
  sgt[root].r = r;
  sgt[root].add = -1;
  if (l == r) {
    for (int i = 0; i < 6; i++)
      sgt[root].sum[i] = (1ll * dat[l] * p[l][i]) % mod;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, root << 1);
  build(mid + 1, r, root << 1 | 1);
  up(root);
}
long long pm(int i, int j) {
  long long ans = 1;
  for (int k = 1; k <= j; k++) {
    ans = (ans * 1ll * i) % mod;
  }
  return ans;
}
void init() {
  memset(cm, 0, sizeof(cm));
  memset(p, 0, sizeof(p));
  memset(s, 0, sizeof(s));
  for (int i = 0; i <= 5; i++) cm[i][i] = cm[i][0] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j < i; j++) cm[i][j] = cm[i - 1][j] + cm[i - 1][j - 1];
  for (int i = 0; i <= 100000; i++) {
    for (int j = 0; j <= 5; j++) {
      p[i][j] = pm(i, j);
    }
  }
  for (int j = 0; j < 6; j++) {
    for (int i = 1; i <= 100000; i++) {
      s[i][j] = (s[i - 1][j] + p[i][j]) % mod;
    }
  }
}
void upd(int l, int r, int val, int root) {
  if (sgt[root].l >= l && sgt[root].r <= r) {
    sgt[root].add = val;
    for (int i = 0; i < 6; i++) {
      sgt[root].sum[i] =
          (1ll * val *
               ((s[sgt[root].r][i] - s[sgt[root].l - 1][i] + mod) % mod) +
           mod) %
          mod;
    }
    return;
  }
  down(root);
  int mid = (sgt[root].l + sgt[root].r) >> 1;
  if (l <= mid) upd(l, r, val, root << 1);
  if (r > mid) upd(l, r, val, root << 1 | 1);
  up(root);
}
long long check(int l, int r, int root, int cifang) {
  if (sgt[root].l >= l && sgt[root].r <= r) return sgt[root].sum[cifang];
  down(root);
  long long ret = 0;
  int mid = (sgt[root].l + sgt[root].r) >> 1;
  if (l <= mid) ret = (ret + check(l, r, root << 1, cifang) + mod) % mod;
  if (r > mid) ret = (ret + check(l, r, root << 1 | 1, cifang) + mod) % mod;
  return ret;
}
int main() {
  init();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &dat[i]);
  build(1, n, 1);
  char choose[5];
  int a, b, c;
  while (m--) {
    scanf("%s %d%d%d", choose, &a, &b, &c);
    if (choose[0] == '=') {
      upd(a, b, c, 1);
    } else if (choose[0] == '?') {
      long long ans;
      long long ttt = 1ll;
      long long output = 0ll;
      for (int i = 0; i <= c; i++) {
        ans = check(a, b, 1, c - i);
        output = (output + ans * cm[c][i] % mod * ttt % mod + mod) % mod;
        ttt = ttt * (1 - a) % mod;
      }
      cout << output << '\n';
    }
  }
}
