#include <bits/stdc++.h>
using namespace std;
int qread() {
  char c;
  int s = 0, f = 1;
  while ((c = getchar()) < '0' || c > '9') (c == '-') && (f = -1);
  do s = s * 10 + c - '0';
  while ((c = getchar()) >= '0' && c <= '9');
  return s * f;
}
int n, m;
const int mod = 1e9 + 7;
int a[100011], pos[100011], bin[100011], inv[100011], sum[100011],
    lp = 0, val[100011], vv[100011], svv[100011];
struct Ques {
  int l, r, id;
  bool operator<(const Ques &b) const { return r < b.r; }
} q[100011];
int ans[100011];
int WWW(long long v) { return v > 2000000001 ? 2000000001 : v; }
int main() {
  n = qread();
  m = qread();
  bin[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++)
    a[i] = qread(), bin[i] = (bin[i - 1] << 1) % mod,
    inv[i] = 1ll * inv[i - 1] * ((mod + 1) >> 1) % mod,
    sum[i] = ((sum[i - 1] + 1ll * a[i] * bin[i]) % mod + mod) % mod;
  for (int i = 1; i <= m; i++) {
    q[i].l = qread();
    q[q[i].id = i].r = qread();
  }
  sort(q + 1, q + 1 + m);
  pos[lp = 1] = 1;
  int j = 1;
  val[1] = a[1] * 2;
  vv[1] = svv[1] = ((a[1] * 2) % mod + mod) % mod;
  while (j <= m && q[j].r == 1) ans[q[j].id] = (a[1] + mod) % mod, j++;
  for (int i = 2; i <= n; i++) {
    if (a[i] <= 0)
      pos[++lp] = i, val[lp] = 2 * a[i],
      vv[lp] = (a[i] * 2ll % mod + mod) % mod,
      svv[lp] = (svv[lp - 1] + vv[lp]) % mod;
    else {
      int cur =
          WWW(0ll + val[lp] + bin[pos[lp] - pos[lp - 1] + 1] * 1ll * a[i]);
      int cvv = (vv[lp] + bin[pos[lp] - pos[lp - 1] + 1] * 1ll * a[i]) % mod;
      lp--;
      while (lp && cur > 0) {
        cur = WWW(0ll + val[lp] +
                  (pos[lp] - pos[lp - 1] > 31 ? 2000000001
                                              : bin[pos[lp] - pos[lp - 1]]) *
                      1ll * cur);
        cvv = (vv[lp] + bin[pos[lp] - pos[lp - 1]] * 1ll * cvv) % mod;
        lp--;
      }
      val[++lp] = cur;
      pos[lp] = i;
      vv[lp] = cvv;
      svv[lp] = (svv[lp - 1] + vv[lp]) % mod;
    }
    while (j <= m && q[j].r == i) {
      if (q[j].l == q[j].r) {
        ans[q[j].id] = (a[i] + mod) % mod;
        j++;
        continue;
      }
      int l = q[j].l + 1, Ans = (a[q[j].l] + mod) % mod;
      int L = 1, R = lp;
      while (L < R) {
        int mid = (L + R) >> 1;
        if (pos[mid] >= l)
          R = mid;
        else
          L = mid + 1;
      }
      Ans = (Ans + svv[lp] - svv[L]) % mod;
      Ans = (Ans + mod) % mod;
      Ans = (Ans + (sum[pos[L]] - sum[l - 1] + mod) * 1ll * inv[l - 1]) % mod;
      ans[q[j].id] = Ans;
      j++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
