#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f2f1f0f;
const long long LINF = 1ll * INF * INF;
const int MAX_N = 1e5 + 100, MOD = 1e9 + 7, LOG_N = 20;
int N, Q, Nr[MAX_N];
long long Sum[MAX_N];
void add(int &a, long long b) {
  b %= MOD;
  if ((a += b) >= MOD) a -= MOD;
  if (a < 0) a += MOD;
}
int Inv2[MAX_N];
int getSum(int a, int b) {
  int val = Sum[b];
  add(val, -Sum[a - 1]);
  return 1ll * val * Inv2[a - 1] % MOD;
}
int P[LOG_N][MAX_N], S[LOG_N][MAX_N];
int main() {
  cin >> N >> Q;
  for (int i = 1; i <= N; i++) scanf("%d", &Nr[i]);
  Inv2[0] = 1;
  for (int i = 1; i <= N; i++)
    Inv2[i] = 1ll * Inv2[i - 1] * (MOD + 1) / 2 % MOD;
  for (int i = 1, p = 2; i <= N; i++) {
    Sum[i] = (Sum[i - 1] + 1ll * Nr[i] * p) % MOD;
    p = (p * 2) % MOD;
  }
  for (int i = 1; i <= N; i++) {
    long long s = 0;
    P[0][i] = 0;
    for (int j = i; j >= 1; j--) {
      s *= 2;
      s += Nr[j];
      if (s <= 0) {
        P[0][i] = j - 1;
        break;
      }
      if (s >= MOD) break;
    }
    S[0][i] = getSum(P[0][i] + 1, i);
  }
  for (int p = 1; p < LOG_N; p++)
    for (int i = 1; i <= N; i++) {
      P[p][i] = P[p - 1][P[p - 1][i]];
      add(S[p][i], S[p - 1][P[p - 1][i]]);
      add(S[p][i], S[p - 1][i]);
    }
  while (Q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    int ans;
    add(ans, Nr[a++]);
    for (int p = LOG_N - 1; p >= 0; p--) {
      if (a <= P[p][b] + 1) {
        add(ans, S[p][b]);
        b = P[p][b];
      }
    }
    if (a <= b) add(ans, getSum(a, b));
    printf("%d\n", ans);
  }
  return 0;
}
