#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
struct query {
  int id, l, r;
  bool operator<(const query& q) const { return r < q.r; }
} q[maxn];
long long a[maxn], ans[maxn], qpow[maxn], sum[maxn], sumx[maxn];
long long idx[maxn], v[maxn], cnt = 0;
long long q_pow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
void add(int id, long long vx) {
  if (cnt == 0 || vx < 0) {
    idx[++cnt] = id;
    v[cnt] = vx;
    sumx[cnt] = (sumx[cnt - 1] + mod + v[cnt]) % mod;
    return;
  }
  int flag = 0;
  while (cnt > 0) {
    long long z = v[cnt];
    long long gap = id - idx[cnt];
    if (gap > 40 || ((long long)1 << gap) > 2e9 || vx > 2e9)
      flag = 1;
    else if (vx * ((long long)1 << gap) > 2e9)
      flag = 1;
    if (flag == 1) break;
    v[cnt] += vx * ((long long)1 << gap);
    id = idx[cnt], vx = v[cnt];
    if (vx <= 0) break;
    cnt--;
  }
  if (cnt == 0) {
    v[++cnt] = vx;
    return;
  }
  if (flag == 1) {
    vx = vx * qpow[id - 1] % mod;
    for (int i = 1; i <= cnt; i++) {
      vx = (vx + mod + v[i]) % mod;
    }
    cnt = 1;
    v[1] = vx;
  }
  sumx[cnt] = (sumx[cnt - 1] + mod + v[cnt]) % mod;
  sumx[cnt] = (sumx[cnt] % mod + mod) % mod;
}
void find(int i, int x) {
  int l = 1, r = cnt;
  int z = -1, id = -1;
  ;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (idx[mid] > x) {
      z = idx[mid];
      id = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  if (id != -1)
    ans[q[i].id] += (2 * (sumx[cnt] + mod - sumx[id - 1]) % mod) % mod;
  if (z == -1) z = q[i].r + 1;
  ans[q[i].id] += ((sum[z - 1] + mod - sum[q[i].l - 1]) % mod) *
                  q_pow(qpow[q[i].l - 1], mod - 2) % mod;
  ans[q[i].id] %= mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  qpow[0] = 1;
  for (int i = 1; i <= n; i++) {
    qpow[i] = qpow[i - 1] * 2 % mod;
    sum[i] = (sum[i - 1] + (a[i] * qpow[i - 1]) % mod) % mod;
    sum[i] = (sum[i] % mod + mod) % mod;
  }
  for (int i = 1; i <= m; i++) {
    cin >> q[i].l >> q[i].r;
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
  int idx = 1;
  for (int i = 1; i <= m; i++) {
    while (idx <= n && idx <= q[i].r) {
      add(idx, a[idx]);
      idx++;
    }
    find(i, q[i].l);
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
