#include <bits/stdc++.h>
int aa;
char ch;
int F() {
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  aa = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') aa = aa * 10 + ch - 48;
  return aa;
}
int n, m, l, r, x, y, k, i, j, c[6][6], ans[6], t[100010 << 2][6],
    set[100010 << 2];
char op;
long long sum[100010][6], ret, tmp;
void bt(int o, int l, int r) {
  set[o] = -1;
  if (l == r) {
    t[o][0] = F() % 1000000007;
    for (int i = 1; i <= 5; i++) t[o][i] = 1LL * t[o][i - 1] * l % 1000000007;
    return;
  }
  int mid = l + r >> 1;
  bt(o << 1, l, mid), bt(o << 1 | 1, mid + 1, r);
  for (int i = 0; i <= 5; i++)
    t[o][i] = (t[o << 1][i] + t[o << 1 | 1][i]) % 1000000007;
}
void query(int o, int l, int r) {
  if (x <= l && r <= y) {
    for (int i = 0; i <= 5; i++)
      ans[i] += t[o][i], ans[i] >= 1000000007 ? ans[i] -= 1000000007 : 1;
    return;
  }
  if (set[o] != -1) {
    l <= x ? l = x : 1, y <= r ? r = y : 1;
    for (int i = 0; i <= 5; i++)
      ans[i] +=
          1LL * (sum[r][i] - sum[l - 1][i] + 1000000007) * set[o] % 1000000007,
          ans[i] >= 1000000007 ? ans[i] -= 1000000007 : 1;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid) query(o << 1, l, mid);
  if (mid < y) query(o << 1 | 1, mid + 1, r);
}
void update(int o, int l, int r) {
  if (x <= l && r <= y) {
    set[o] = k;
    for (int i = 0; i <= 5; i++)
      t[o][i] = 1LL * (sum[r][i] - sum[l - 1][i] + 1000000007) * k % 1000000007;
    return;
  }
  int mid = l + r >> 1;
  if (set[o] != -1) {
    set[o << 1] = set[o << 1 | 1] = set[o];
    for (int i = 0; i <= 5; i++)
      t[o << 1][i] = 1LL * (sum[mid][i] - sum[l - 1][i] + 1000000007) * set[o] %
                     1000000007,
             t[o << 1 | 1][i] = 1LL * (sum[r][i] - sum[mid][i] + 1000000007) *
                                set[o] % 1000000007;
    set[o] = -1;
  }
  if (x <= mid) update(o << 1, l, mid);
  if (mid < y) update(o << 1 | 1, mid + 1, r);
  for (int i = 0; i <= 5; i++)
    t[o][i] = (t[o << 1][i] + t[o << 1 | 1][i]) % 1000000007;
}
int main() {
  for (c[0][0] = 1, i = 1; i <= 5; i++)
    for (c[i][0] = 1, j = 1; j <= i; j++)
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  for (n = F(), m = F(), i = 1; i <= n; i++) {
    for (sum[i][0] = 1, j = 1; j <= 5; j++)
      sum[i][j] = sum[i][j - 1] * i % 1000000007;
    for (j = 0; j <= 5; j++)
      sum[i][j] = (sum[i][j] + sum[i - 1][j]) % 1000000007;
  }
  for (bt(1, 1, n); m--;) {
    while (op = getchar(), op != '=' && op != '?')
      ;
    x = F(), y = F(), k = F() % 1000000007;
    if (op == '?') {
      for (i = 0; i <= 5; i++) ans[i] = 0;
      query(1, 1, n);
      for (i = ret = 0, tmp = 1; i <= k;
           i++, tmp = tmp * (x - 1) % 1000000007, ret %= 1000000007)
        if (i & 1)
          ret += 1000000007 -
                 1LL * c[k][i] * tmp % 1000000007 * ans[k - i] % 1000000007;
        else
          ret += 1LL * c[k][i] * tmp % 1000000007 * ans[k - i] % 1000000007;
      ret %= 1000000007, ret < 0 ? ret += 1000000007 : 1;
      printf("%I64d\n", ret);
    } else
      update(1, 1, n);
  }
}
