#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
const long long MAX_LOG = 20;
const long long INF = 1e9 + 10;
const long long Mod = 1e9 + 7;
long long w[MAXN][MAX_LOG];
long long dp[MAXN][MAX_LOG];
long long a[MAXN];
long long ps[MAXN];
long long pw2[MAXN];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n, q;
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = n; i >= 1; i--) {
    ps[i] = ps[i + 1] * 2 + (Mod + a[i]);
    ps[i] %= Mod;
  }
  pw2[0] = 1;
  for (long long i = 1; i < MAXN; i++) {
    pw2[i] = pw2[i - 1] * 2;
    pw2[i] %= Mod;
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i] < 0) {
      dp[i][0] = i - 1;
    }
    if (a[i] >= 0) {
      dp[i][0] = i - 1;
      long long x = a[i];
      while (dp[i][0] > 0) {
        if (x == 0) {
          dp[i][0] = dp[dp[i][0]][0];
          break;
        }
        if (x > INF) {
          dp[i][0] = 0;
          break;
        }
        if (2 * x >= -a[dp[i][0]]) {
          x = 2 * x + a[dp[i][0]];
          dp[i][0]--;
        } else {
          dp[i][0]--;
          break;
        }
      }
    }
    w[i][0] = ps[dp[i][0] + 1] - ((pw2[i - dp[i][0]] * ps[i + 1]) % Mod) + Mod;
    w[i][0] %= Mod;
  }
  for (long long i = 1; i < MAX_LOG; i++) {
    for (long long j = 1; j <= n; j++) {
      dp[j][i] = dp[dp[j][i - 1]][i - 1];
      w[j][i] = w[j][i - 1] + w[dp[j][i - 1]][i - 1];
      w[j][i] %= Mod;
    }
  }
  for (long long i = 1; i <= q; i++) {
    long long l, r;
    cin >> l >> r;
    long long res = 0;
    for (long long j = MAX_LOG - 1; j >= 0; j--) {
      if (dp[r][j] >= l) {
        res += w[r][j];
        res %= Mod;
        r = dp[r][j];
      }
    }
    res *= 2;
    res %= Mod;
    res += ps[l] - ((pw2[r - l + 1] * ps[r + 1]) % Mod) + Mod;
    res %= Mod;
    cout << res << endl;
  }
}
