#include <bits/stdc++.h>
using namespace std;
int n, m;
int conf[6][100111];
struct seg {
  int length;
  vector<vector<int> > arr;
  vector<bool> arrt;
  seg(int height) {
    length = 1 << height;
    arr.resize(length * 2, vector<int>(6));
    arrt.resize(length * 2, false);
  }
  void range_as(int l, int r, int loc, int len, int &val) {
    if (loc * len >= l && (loc + 1) * len <= r) {
      arr[loc][0] = val;
      arrt[loc] = true;
    } else if (loc * len < r && (loc + 1) * len > l) {
      if (arrt[loc]) {
        arrt[loc] = false;
        int val2 = arr[loc][0];
        if (loc * len < l) {
          range_as(loc * len, l, loc, len, val2);
        }
        if ((loc + 1) * len > r) {
          range_as(r, (loc + 1) * len, loc, len, val2);
        }
      }
      range_as(l, r, loc * 2, len / 2, val);
      range_as(l, r, loc * 2 + 1, len / 2, val);
      for (int i = 0; i < 6; ++i) {
        if (arrt[loc * 2]) {
          arr[loc][i] =
              ((long long)(conf[i][(loc * 2 + 1) * (len / 2) - length] -
                           conf[i][loc * len - length]) *
               arr[loc * 2][0]) %
              1000000007;
        } else {
          arr[loc][i] = arr[loc * 2][i];
        }
        if (arrt[loc * 2 + 1]) {
          arr[loc][i] =
              ((long long)(conf[i][(loc + 1) * len - length] -
                           conf[i][(loc * 2 + 1) * (len / 2) - length]) *
                   arr[loc * 2 + 1][0] +
               arr[loc][i]) %
              1000000007;
        } else {
          arr[loc][i] = (arr[loc][i] + arr[loc * 2 + 1][i]) % 1000000007;
        }
      }
    }
  }
  void range_assign(int l, int r, int val) {
    range_as(l + length, r + length, 1, length, val);
  }
  void range_sum(int l, int r, int loc, int len, int &ra, int &res) {
    if (arrt[loc]) {
      if (min(r, (loc + 1) * len) > max(l, loc * len)) {
        res = ((long long)(conf[ra][min(r, (loc + 1) * len) - length] -
                           conf[ra][max(l, loc * len) - length]) *
                   arr[loc][0] +
               res) %
              1000000007;
      }
    } else {
      if (loc * len >= l && (loc + 1) * len <= r) {
        res = (res + arr[loc][ra]) % 1000000007;
      } else if (loc * len < r && (loc + 1) * len > l) {
        range_sum(l, r, loc * 2, len / 2, ra, res);
        range_sum(l, r, loc * 2 + 1, len / 2, ra, res);
      }
    }
  }
  int querry(int l, int r, int ra) {
    int res = 0;
    range_sum(l + length, r + length, 1, length, ra, res);
    return (res + 1000000007) % 1000000007;
  }
};
int combs[11][11];
int main() {
  combs[0][0] = 1;
  for (int i = 1; i < 9; ++i) {
    combs[i][0] = 1;
    for (int j = 1; j < 9; ++j) {
      combs[i][j] = combs[i - 1][j] + combs[i - 1][j - 1];
    }
  }
  for (int i = 0; i < 9; ++i) {
    for (int j = 0; j < 9; ++j) {
      if (j % 2) {
        combs[i][j] = -combs[i][j];
      }
    }
  }
  scanf("%d %d", &n, &m);
  for (int j = 0; j <= n; ++j) {
    conf[0][j] = j;
  }
  for (int i = 1; i < 6; ++i) {
    for (int j = 1; j <= n; ++j) {
      conf[i][j] = ((long long)(conf[i - 1][j] - conf[i - 1][j - 1]) * j +
                    conf[i][j - 1]) %
                   1000000007;
    }
  }
  seg tree(17);
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    tree.range_assign(i, i + 1, a);
  }
  for (int i = 0; i < m; ++i) {
    char type;
    int l, r, x;
    scanf(" %c %d %d %d", &type, &l, &r, &x);
    if (type == '=') {
      tree.range_assign(l - 1, r, x);
    } else {
      int res = 0;
      int pos = 1;
      for (int i = 0; i <= x; ++i) {
        res = ((long long)pos * combs[x][i] % 1000000007 *
                   tree.querry(l - 1, r, x - i) +
               res) %
              1000000007;
        pos = ((long long)pos * (l - 1)) % 1000000007;
      }
      res = (res + 1000000007) % 1000000007;
      printf("%d\n", res);
    }
  }
  return 0;
}
