#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
const int MAXNODE = MAXN << 2;
const int MOD = 1000000007;
int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
int mul(int a, int b) {
  return !b || a < MOD / b ? a * b : (long long)a * b % MOD;
}
int C[6][6], matrix[6][6], accsum[6][MAXN];
void init() {
  for (int i = 0; i < 6; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) {
      C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
    }
  }
  for (int i = 1; i < 6; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k <= j; k++) {
        matrix[i][i - 1 - k] = add(matrix[i][i - 1 - k], C[j][k]);
      }
    }
  }
  for (int j = 1; j < MAXN; j++) {
    accsum[0][j] = 1;
  }
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j < MAXN; j++) {
      accsum[i][j] = mul(accsum[i - 1][j], j);
    }
  }
  for (int i = 0; i < 6; i++) {
    for (int j = 1; j < MAXN; j++) {
      accsum[i][j] = add(accsum[i][j], accsum[i][j - 1]);
    }
  }
}
class Segment {
 public:
  int size, value, sum[6];
  bool tag;
  Segment() {
    size = value = 0;
    tag = false;
    for (int i = 0; i < 6; i++) {
      sum[i] = 0;
    }
  }
  Segment(int size, int value, bool tag) : size(size), value(value), tag(tag) {
    for (int i = 0; i < 6; i++) {
      sum[i] = tag ? mul(value, accsum[i][size]) : 0;
    }
  }
  Segment operator+(const Segment &rhs) const {
    Segment res = Segment(size + rhs.size, 0, false);
    for (int i = 0; i < 6; i++) {
      res.sum[i] = add(sum[i], rhs.sum[i]);
      int l = 1;
      for (int j = i - 1; j >= 0; j--) {
        l = mul(l, size);
        res.sum[i] = add(res.sum[i], mul(rhs.sum[j], mul(matrix[i][j], l)));
      }
    }
    return res;
  }
};
int a[MAXN];
class SegTree {
 public:
  int n;
  Segment seg[MAXNODE];
  static int LEFT(int idx) { return idx << 1; }
  static int RIGHT(int idx) { return (idx << 1) | 1; }
  void _build(int idx, int lower, int upper) {
    if (lower == upper) {
      seg[idx] = Segment(1, a[lower], true);
      return;
    }
    int middle = (lower + upper) >> 1;
    _build(LEFT(idx), lower, middle);
    _build(RIGHT(idx), middle + 1, upper);
    seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];
  }
  void init(int n) {
    this->n = n;
    _build(1, 0, n - 1);
  }
  void pushDown(int idx) {
    if (seg[idx].tag) {
      seg[LEFT(idx)] = Segment(seg[LEFT(idx)].size, seg[idx].value, true);
      seg[RIGHT(idx)] = Segment(seg[RIGHT(idx)].size, seg[idx].value, true);
      seg[idx].tag = false;
    }
  }
  int l, r, v;
  void _modify(int idx, int lower, int upper) {
    if (r < lower || upper < l) {
      return;
    }
    if (l <= lower && upper <= r) {
      seg[idx] = Segment(upper - lower + 1, v, true);
      return;
    }
    pushDown(idx);
    int middle = (lower + upper) >> 1;
    _modify(LEFT(idx), lower, middle);
    _modify(RIGHT(idx), middle + 1, upper);
    seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];
  }
  void modify(int l, int r, int value) {
    this->l = l;
    this->r = r;
    this->v = value;
    _modify(1, 0, n - 1);
  }
  Segment _calc(int idx, int lower, int upper) {
    if (r < lower || upper < l) {
      return Segment();
    }
    if (l <= lower && upper <= r) {
      return seg[idx];
    }
    pushDown(idx);
    int middle = (lower + upper) >> 1;
    return _calc(LEFT(idx), lower, middle) +
           _calc(RIGHT(idx), middle + 1, upper);
  }
  Segment calc(int l, int r) {
    this->l = l;
    this->r = r;
    return _calc(1, 0, n - 1);
  }
};
int n, m;
SegTree st;
int main() {
  init();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  st.init(n);
  for (int i = 0; i < m; i++) {
    char op[4];
    int l, r, x;
    scanf("%s%d%d%d", op, &l, &r, &x);
    if (op[0] == '?') {
      Segment sg = st.calc(l - 1, r - 1);
      printf("%d\n", sg.sum[x]);
    } else {
      st.modify(l - 1, r - 1, x);
    }
  }
  return 0;
}
