#include <bits/stdc++.h>
using namespace std;
int IT_MAX = 1 << 17;
const long long MOD = 1000000007;
long long functie1(long long a, long long b = MOD) {
  long long t1 = a, t2 = b, t3;
  long long v1 = 1, v2 = 0, v3;
  while (t2 != 1) {
    long long x = t1 / t2;
    t3 = t1 - x * t2;
    v3 = v1 - x * v2;
    t1 = t2, t2 = t3;
    v1 = v2, v2 = v3;
  }
  return (v2 + b) % b;
}
long long in[100050];
long long sum[100050];
long long po2[100050];
long long functie2(int p1, int p2) {
  long long rv = sum[p2] - sum[p1 - 1];
  rv = (rv + MOD) % MOD;
  rv = rv * functie1(po2[p1 - 1]) % MOD;
  return rv;
}
long long urm[100050][2];
long long par[20][100050][2];
int main() {
  int n, q, i, j;
  scanf("%d %d", &n, &q);
  po2[0] = 1;
  for (i = 1; i <= n; i++) po2[i] = po2[i - 1] * 2 % MOD;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &in[i]);
    sum[i] = sum[i - 1] + in[i] * po2[i];
    sum[i] %= MOD;
    sum[i] += MOD;
    sum[i] %= MOD;
  }
  for (i = 1; i <= n; i++) {
    long long s = 0;
    for (j = i; j >= 1; j--) {
      s = 2 * s + in[j];
      if (s <= 0) {
        urm[i][0] = j - 1;
        break;
      }
      if (s >= 1000000000) break;
    }
    urm[i][1] = functie2(urm[i][0] + 1, i);
  }
  for (i = 0; i <= n; i++) par[0][i][0] = urm[i][0], par[0][i][1] = urm[i][1];
  for (i = 1; i < 20; i++) {
    for (j = 1; j <= n; j++) {
      int np = par[i - 1][j][0];
      par[i][j][0] = par[i - 1][np][0];
      par[i][j][1] = (par[i - 1][j][1] + par[i - 1][np][1]) % MOD;
    }
  }
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    if (l == r) {
      printf("%lld\n", (in[l] + 2 * MOD) % MOD);
      continue;
    }
    long long ans = (in[l] + MOD) % MOD;
    l++;
    for (i = 19; i >= 0; i--) {
      int p = par[i][r][0];
      if (p >= l) {
        ans = (ans + par[i][r][1]) % MOD;
        r = p;
      }
    }
    ans += functie2(l, r);
    printf("%lld\n", ans % MOD);
  }
  return 0;
}
