#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
const long long inf = 1000000000000000;
int ans[100005], a[100005], L[100005], d[100005], u, n, m, Q, l, r, t, p;
long long x, H[100005], NH[100005], b[100005], h[100005], f[100005], F[100005],
    W[100005];
struct O {
  int i, l;
};
vector<O> G[100005];
long long X(long long x, long long y) {
  if ((long double)x * y > inf) return inf;
  if ((long double)x * y < -inf) return -inf;
  return x * y;
}
long long qiu(int l, int r) { return (b[r] - b[l - 1] + mo) * NH[l - 1] % mo; }
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  NH[0] = H[0] = 1;
  for (int i = 1; i <= n; ++i) H[i] = H[i - 1] * 2 % mo;
  NH[1] = mo + 1 >> 1;
  for (int i = 2; i <= n; ++i) NH[i] = NH[i - 1] * NH[1] % mo;
  for (int i = 1; i <= n; ++i) b[i] = (H[i - 1] * a[i] % mo + b[i - 1]) % mo;
  h[0] = 1;
  for (int i = 1; i <= n; ++i) h[i] = min(h[i - 1] * 2, inf);
  for (int i = 1, j; i <= n; ++i) {
    for (x = a[i], j = i - 1; j; j = L[j]) {
      if (x <= 0 || x == inf) break;
      x = min(X(x, h[j - L[j]]) + f[j], inf);
    }
    L[i] = x == inf ? 0 : j;
    f[i] = x;
    F[i] = qiu(L[i] + 1, i) * 2 % mo;
  }
  for (int i = 1; i <= Q; ++i) {
    scanf("%d%d", &l, &r);
    G[r].push_back((O){i, l});
  }
  for (int i = 1; i <= n; ++i) {
    while (t && d[t] > L[i]) --t;
    d[++t] = i;
    W[t] = (W[t - 1] + F[i]) % mo;
    for (int j = 0; j < (int)G[i].size(); ++j) {
      u = G[i][j].l;
      p = lower_bound(d + 1, d + t + 1, u) - d;
      ans[G[i][j].i] = ((W[t] - W[p] + qiu(u, d[p])) % mo + mo) % mo;
    }
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}
