#include <bits/stdc++.h>
using namespace std;
long long s[100010][6];
long long sum[400010][6];
long long num[400010];
long long ans[6];
int n, m;
int x, k;
char ch[3];
int l, r;
long long calc(int l, int r, int k) {
  return ((s[r][k] - s[l - 1][k]) % 1000000007 + 1000000007) % 1000000007;
}
void pushup(int rt) {
  for (int i = 0; i <= 5; i++) {
    sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i];
  }
}
void pushdown(int rt, int l, int r) {
  if (num[rt] != -1) {
    int mid = (l + r) >> 1;
    num[rt << 1] = num[rt];
    num[rt << 1 | 1] = num[rt];
    for (int i = 0; i <= 5; i++) {
      sum[rt << 1][i] = num[rt] * calc(l, mid, i) % 1000000007;
      sum[rt << 1 | 1][i] = num[rt] * calc(mid + 1, r, i) % 1000000007;
    }
    num[rt] = -1;
  }
}
void build(int rt, int l, int r) {
  num[rt] = -1;
  if (l == r) {
    scanf("%d", &x);
    for (int i = 0; i <= 5; i++) {
      sum[rt][i] = 1ll * x * calc(l, l, i) % 1000000007;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  pushup(rt);
}
void change(int rt, int l, int r, int L, int R, int k) {
  if (L <= l && r <= R) {
    num[rt] = 1ll * k;
    for (int i = 0; i <= 5; i++) {
      sum[rt][i] = 1ll * k * calc(l, r, i) % 1000000007;
    }
    return;
  }
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) {
    change(rt << 1, l, mid, L, R, k);
  }
  if (R > mid) {
    change(rt << 1 | 1, mid + 1, r, L, R, k);
  }
  pushup(rt);
}
void query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    for (int i = 0; i <= 5; i++) {
      ans[i] += sum[rt][i];
      ans[i] %= 1000000007;
    }
    return;
  }
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) {
    query(rt << 1, l, mid, L, R);
  }
  if (R > mid) {
    query(rt << 1 | 1, mid + 1, r, L, R);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    s[i][0] = 1ll;
    for (int j = 1; j <= 5; j++) {
      s[i][j] = s[i][j - 1] * i % 1000000007;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 5; j++) {
      s[i][j] += s[i - 1][j];
      s[i][j] %= 1000000007;
    }
  }
  build(1, 1, n);
  while (m--) {
    scanf("%s%d%d%d", ch, &l, &r, &k);
    if (ch[0] == '=') {
      change(1, 1, n, l, r, k);
    } else {
      memset(ans, 0, sizeof(ans));
      query(1, 1, n, l, r);
      long long res = 0;
      if (k == 0) {
        res += ans[0], res %= 1000000007;
      } else if (k == 1) {
        res += ans[1], res %= 1000000007;
        res -= 1ll * (l - 1) * ans[0] % 1000000007, res %= 1000000007;
      } else if (k == 2) {
        res += ans[2], res %= 1000000007;
        res -= 2ll * (l - 1) * ans[1] % 1000000007, res %= 1000000007;
        res += 1ll * (l - 1) * (l - 1) % 1000000007 * ans[0] % 1000000007,
            res %= 1000000007;
      } else if (k == 3) {
        res += ans[3], res %= 1000000007;
        res -= 3ll * (l - 1) * ans[2] % 1000000007, res %= 1000000007;
        res += 3ll * (l - 1) * (l - 1) % 1000000007 * ans[1] % 1000000007,
            res %= 1000000007;
        res -= 1ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               ans[0] % 1000000007,
            res %= 1000000007;
      } else if (k == 4) {
        res += ans[4], res %= 1000000007;
        res -= 4ll * (l - 1) * ans[3] % 1000000007, res %= 1000000007;
        res += 6ll * (l - 1) * (l - 1) % 1000000007 * ans[2] % 1000000007,
            res %= 1000000007;
        res -= 4ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               ans[1] % 1000000007,
            res %= 1000000007;
        res += 1ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               (l - 1) % 1000000007 * ans[0] % 1000000007,
            res %= 1000000007;
      } else {
        res += ans[5], res %= 1000000007;
        res -= 5ll * (l - 1) * ans[4] % 1000000007, res %= 1000000007;
        res += 10ll * (l - 1) * (l - 1) % 1000000007 * ans[3] % 1000000007,
            res %= 1000000007;
        res -= 10ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               ans[2] % 1000000007,
            res %= 1000000007;
        res += 5ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               (l - 1) % 1000000007 * ans[1] % 1000000007,
            res %= 1000000007;
        res -= 1ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               (l - 1) % 1000000007 * (l - 1) % 1000000007 * ans[0] %
               1000000007,
            res %= 1000000007;
      }
      res = (res % 1000000007 + 1000000007) % 1000000007;
      printf("%lld\n", res);
    }
  }
}
