#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
long long c[10][10], s[100020][6];
void init() {
  c[0][0] = 1;
  for (int i = 1; i <= 6; ++i) {
    c[i][0] = 1;
    for (int j = 1; j <= i; ++j) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  }
  for (int i = 0; i < 100020; ++i) {
    for (int j = 0; j < 6; ++j) {
      s[i][j] = 1;
      for (int k = 0; k < j; ++k) s[i][j] = s[i][j] * i % 1000000007;
    }
  }
  for (int i = 1; i < 100020; ++i)
    for (int j = 0; j < 6; ++j) s[i][j] = (s[i][j] + s[i - 1][j]) % 1000000007;
}
long long sum[100020 << 2][6];
int down[100020 << 2];
void f(int v, int ll, int rr, int i) {
  down[i] = v;
  for (int j = 0; j < 6; ++j)
    sum[i][j] =
        (s[rr][j] - s[ll - 1][j] + 1000000007) % 1000000007 * v % 1000000007;
}
void push_down(int i, int ll, int rr) {
  if (~down[i]) {
    f(down[i], ll, ((ll + rr) >> 1), (i << 1));
    f(down[i], ((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
    down[i] = -1;
  }
}
void push_up(int i) {
  for (int j = 0; j < 6; ++j)
    sum[i][j] = (sum[(i << 1)][j] + sum[((i << 1) | 1)][j]) % 1000000007;
}
void build(int ll, int rr, int i) {
  down[i] = -1;
  if (ll == rr) {
    int v;
    scanf("%d", &v);
    for (int j = 0; j < 6; ++j)
      sum[i][j] =
          (s[rr][j] - s[rr - 1][j] + 1000000007) % 1000000007 * v % 1000000007;
    return;
  }
  build(ll, ((ll + rr) >> 1), (i << 1)),
      build(((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
  push_up(i);
}
void update(int l, int r, int v, int ll, int rr, int i) {
  if (l == ll && r == rr) {
    f(v, ll, rr, i);
    return;
  }
  push_down(i, ll, rr);
  if (r <= ((ll + rr) >> 1))
    update(l, r, v, ll, ((ll + rr) >> 1), (i << 1));
  else if (l > ((ll + rr) >> 1))
    update(l, r, v, ((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
  else
    update(l, ((ll + rr) >> 1), v, ll, ((ll + rr) >> 1), (i << 1)),
        update(((ll + rr) >> 1) + 1, r, v, ((ll + rr) >> 1) + 1, rr,
               ((i << 1) | 1));
  push_up(i);
}
long long query(int l, int r, int p, int v, int ll, int rr, int i) {
  if (l == ll && r == rr) {
    long long ret = 0, tmp = 1;
    for (int j = v; j >= 0; --j) {
      ret = (ret + sum[i][j] * c[v][j] % 1000000007 * tmp % 1000000007 +
             1000000007) %
            1000000007;
      tmp = tmp * (1 - p) % 1000000007;
    }
    return ret;
  }
  push_down(i, ll, rr);
  long long ret;
  if (r <= ((ll + rr) >> 1))
    ret = query(l, r, p, v, ll, ((ll + rr) >> 1), (i << 1));
  else if (l > ((ll + rr) >> 1))
    ret = query(l, r, p, v, ((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
  else
    ret = (query(l, ((ll + rr) >> 1), p, v, ll, ((ll + rr) >> 1), (i << 1)) +
           query(((ll + rr) >> 1) + 1, r, p, v, ((ll + rr) >> 1) + 1, rr,
                 ((i << 1) | 1))) %
          1000000007;
  push_up(i);
  return ret;
}
int main() {
  init();
  int n, m;
  scanf("%d%d", &n, &m);
  build(1, n, 1);
  while (m--) {
    int L, R, k;
    char ch[5];
    scanf("%s%d%d%d", &ch, &L, &R, &k);
    if (ch[0] == '=')
      update(L, R, k, 1, n, 1);
    else
      printf("%I64d\n", query(L, R, L, k, 1, n, 1));
  }
  return 0;
}
