#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[100050], sum[100050], sum2[100050], pre[100050];
long long pow2[100050];
struct node {
  long long l, r, id;
} q[100050];
long long cnt;
long long k[100050], ans[100050];
long long f[100050];
long long lg[100050];
long long find(long long x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = find(f[x]);
}
long long ask(long long x, long long y) {
  return (sum2[x] - sum2[y + 1] * pow2[y - x + 1] % 1000000007 + 1000000007) %
         1000000007;
}
void merge(long long x, long long y) {
  if ((x - pre[x] > 31 && sum[y] > 0) ||
      sum[x] + (sum[y] << (x - pre[x])) > 1000000007)
    sum[y] = 1000000007;
  else
    sum[y] = sum[x] + (sum[y] << (x - pre[x]));
  f[x] = f[y];
  pre[y] = pre[x];
}
bool comp(node aa, node bb) { return aa.r < bb.r; }
signed main() {
  scanf("%lld%lld", &n, &m);
  pow2[0] = 1;
  for (register long long i = 1; i <= n; i++) {
    f[i] = i;
    pre[i] = i - 1;
    scanf("%lld", &a[i]);
    pow2[i] = (pow2[i - 1] << 1) % 1000000007;
    sum[i] = a[i];
  }
  for (register long long i = 1; i <= m; i++) {
    long long a1, a2;
    scanf("%lld%lld", &a1, &a2);
    q[i] = {a1, a2, i};
  }
  for (register long long i = n; i >= 1; i--) {
    sum2[i] = ((sum2[i + 1] << 1) + a[i] + 1000000007) % 1000000007;
  }
  sort(q + 1, q + 1 + m, comp);
  long long now = 0;
  for (register long long i = 1; i <= n; i++) {
    while (sum[i] >= 0 && pre[i]) merge(pre[i], i);
    k[i] = (k[pre[i]] + (ask(pre[i] + 1, i) << 1) % 1000000007 + 1000000007) %
           1000000007;
    while (q[now + 1].r == i) {
      long long fa = find(q[++now].l);
      ans[q[now].id] =
          (k[i] - k[fa] + ask(q[now].l, fa) + 1000000007) % 1000000007;
    }
  }
  for (register long long i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
  return 0;
}
