#include <bits/stdc++.h>
using namespace std;
int p[100010], n, m;
long long r[100010], s[100010], tw[100010], a[100010], b[100010], v[100010],
    aa[100010], t[100010];
int fd(int x) { return !p[x] ? x : p[x] = fd(p[x]); }
int qu(int x, int y) {
  return (t[x] - t[y + 1] * tw[y - x + 1] % 1000000007 + 1000000007) %
         1000000007;
}
struct no {
  int l, r, i;
} q[100010];
int operator<(no x, no y) { return x.r < y.r; }
void mg(int x, int y) {
  p[x] = y;
  b[y] = b[x];
  if ((x - b[x] > 30 && s[y] > 0) || (s[x] + (s[y] << (x - b[x]))) > 1000000007)
    s[y] = 1000000007;
  else
    s[y] = s[x] + (s[y] << (x - b[x]));
}
int main() {
  cin >> n >> m;
  tw[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    s[i] = a[i];
    tw[i] = tw[i - 1] * 2 % 1000000007;
    b[i] = i - 1;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].i = i;
  }
  sort(q + 1, q + m + 1);
  for (int i = n; i; i--)
    t[i] = (t[i + 1] * 2 + a[i] + 1000000007) % 1000000007;
  int p = 1;
  for (int i = 1; i <= n; i++) {
    while (s[i] >= 0 && b[i]) mg(b[i], i);
    v[i] =
        (v[b[i]] + qu(b[i] + 1, i) * 2 % 1000000007 + 1000000007) % 1000000007;
    while (q[p].r == i) {
      int x = fd(q[p].l);
      aa[q[p].i] = (v[i] - v[x] + qu(q[p].l, x) + 1000000007) % 1000000007;
      p++;
    }
  }
  for (int i = 1; i <= m; i++) cout << aa[i] << '\n';
}
