#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;
const long long INF = (long long)1e18;
int n, Q;
long long a[N], sum[N], two[N], rev[N], second[18][N], l[18][N];
long long bp(long long x, long long y) {
  long long z = 1;
  while (y) {
    if (y & 1) z = z * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return z;
}
long long get(long long l, long long r) {
  return ((sum[r] - sum[l - 1] + mod) % mod) * rev[l - 1] % mod;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(NULL);
  cin >> n >> Q;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  two[0] = rev[0] = 1;
  for (int i = 1; i <= n; ++i) {
    two[i] = two[i - 1] * 2 % mod;
    rev[i] = bp(two[i], mod - 2);
  }
  for (int i = 1; i <= n; ++i)
    sum[i] = (sum[i - 1] + a[i] * two[i] % mod + mod) % mod;
  for (int i = 1; i <= n; ++i) {
    long long x = 0;
    l[0][i] = 0;
    for (int j = i; j >= 1; --j) {
      x = (x + a[j]) * 2;
      if (x <= 0) {
        l[0][i] = j - 1;
        break;
      }
      if (x >= (long long)1e18) {
        l[0][i] = 0;
        break;
      }
    }
    second[0][i] = get(l[0][i] + 1, i);
  }
  for (int j = 1; j <= 17; ++j)
    for (int i = 1; i <= n; ++i) {
      l[j][i] = l[j - 1][l[j - 1][i]];
      second[j][i] = (second[j - 1][i] + second[j - 1][l[j - 1][i]]) % mod;
    }
  while (Q--) {
    int L, R;
    cin >> L >> R;
    long long ans = 0;
    for (int i = 17; i >= 0; --i) {
      if (l[i][R] >= L) {
        ans = (ans + second[i][R]) % mod;
        R = l[i][R];
      }
    }
    ans = (ans + get(L, R) * rev[1]) % mod;
    cout << ans << endl;
  }
  return 0;
}
