#include <bits/stdc++.h>
using namespace std;
const int coef[6][6] = {{1, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0},
                        {1, 2, 1, 0, 0, 0}, {1, 3, 3, 1, 0, 0},
                        {1, 4, 6, 4, 1, 0}, {1, 5, 10, 10, 5, 1}};
const int DIM = 100005;
const int MOD = 1e9 + 7;
int lzy[DIM * 4], sgt[6][DIM * 4], psm[6][DIM], arr[DIM];
int pwr(int x, int y) {
  int ans = 1;
  x = (x % MOD + MOD) % MOD;
  for (int i = 1; i <= y; ++i) ans = 1LL * ans * x % MOD;
  return ans;
}
void updateLazy(int nd, int le, int ri) {
  if (lzy[nd] != -1) {
    for (int k = 0; k <= 5; ++k)
      sgt[k][nd] = 1LL * lzy[nd] * (psm[k][ri] - psm[k][le - 1] + MOD) % MOD;
    if (le != ri) lzy[nd * 2] = lzy[nd * 2 + 1] = lzy[nd];
    lzy[nd] = -1;
  }
}
void updateNode(int nd, int le, int ri) {
  for (int k = 0; k <= 5; ++k)
    sgt[k][nd] = (sgt[k][nd * 2] + sgt[k][nd * 2 + 1]) % MOD;
}
void build(int nd, int le, int ri) {
  lzy[nd] = -1;
  if (le == ri) {
    for (int k = 0; k <= 5; ++k)
      sgt[k][nd] = 1LL * (psm[k][le] - psm[k][le - 1] + MOD) * arr[le] % MOD;
  } else {
    int md = (le + ri) / 2;
    build(nd * 2, le, md);
    build(nd * 2 + 1, md + 1, ri);
    updateNode(nd, le, ri);
  }
}
void update(int nd, int le, int ri, int st, int en, int vl) {
  updateLazy(nd, le, ri);
  if (en < le or ri < st) return;
  if (st <= le and ri <= en) {
    lzy[nd] = vl;
    updateLazy(nd, le, ri);
  } else {
    int md = (le + ri) / 2;
    update(nd * 2, le, md, st, en, vl);
    update(nd * 2 + 1, md + 1, ri, st, en, vl);
    updateNode(nd, le, ri);
  }
}
int v[6];
void query(int nd, int le, int ri, int st, int en) {
  updateLazy(nd, le, ri);
  if (en < le or ri < st) return;
  if (st <= le and ri <= en) {
    for (int k = 0; k <= 5; ++k) v[k] = (v[k] + sgt[k][nd]) % MOD;
  } else {
    int md = (le + ri) / 2;
    query(nd * 2, le, md, st, en);
    query(nd * 2 + 1, md + 1, ri, st, en);
  }
}
int main(void) {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  for (int k = 0; k <= 5; ++k)
    for (int i = 1; i <= n; ++i) psm[k][i] = (pwr(i, k) + psm[k][i - 1]) % MOD;
  build(1, 1, n);
  while (q--) {
    char ch;
    int l, r, x;
    cin >> ch >> l >> r >> x;
    if (ch == '=')
      update(1, 1, n, l, r, x);
    else {
      for (int k = 0; k <= 5; ++k) v[k] = 0;
      query(1, 1, n, l, r);
      int ans = 0;
      for (int k = 0; k <= x; ++k)
        ans = (1LL * coef[x][k] * v[k] % MOD * pwr(1 - l, x - k) + ans) % MOD;
      cout << (ans % MOD + MOD) % MOD << "\n";
    }
  }
  return 0;
}
