#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<int, int>;
using pi3 = pair<int, pii>;
const int NN = 101010;
const int inf = 1e9 + 10;
const int mod = 1e9 + 7;
int pw[NN], a[NN], b[NN], ans[NN], rev[NN];
vector<pii> qr[NN];
vector<pi3> buf;
int calc_sum(int L, int R) {
  return (INT)(b[R] - b[L - 1] + mod) % mod * rev[L - 1] % mod;
}
int calc(int L, int R) {
  auto id = lower_bound(buf.begin(), buf.end(), pi3(L + 1, pii(-inf, -inf))) -
            buf.begin() - 1;
  if (id == buf.size() - 1) return calc_sum(L, R);
  return (calc_sum(L, buf[id + 1].first - 1) +
          2ll * (buf.back().second.second - buf[id].second.second + mod)) %
         mod;
}
int main() {
  for (int i = pw[0] = rev[0] = 1; i < NN; i++) {
    pw[i] = pw[i - 1] * 2 % mod;
    rev[i] = rev[i - 1] * 500000004ll % mod;
  }
  int n, Q;
  cin >> n >> Q;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    b[i] = (INT)a[i] * pw[i - 1] % mod;
    b[i] = ((INT)b[i - 1] + b[i] + mod) % mod;
  }
  for (int i = 1; i <= Q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    qr[r].push_back({l, i});
  }
  for (int i = 1; i <= n; i++) {
    int s = a[i], smod = (a[i] % mod + mod) % mod, pos = i;
    while (!buf.empty()) {
      if (s <= 0) break;
      auto p = buf.back();
      buf.pop_back();
      int len = pos - p.first;
      pos = p.first;
      if (len >= 30 || s >= inf)
        s = inf;
      else
        s = min((INT)inf, (INT)pw[len] * s + p.second.first);
      smod = ((INT)smod * pw[len] + p.second.second) % mod;
      if (buf.size()) {
        smod = (smod - buf.back().second.second + mod) % mod;
      }
    }
    buf.push_back(
        {pos,
         {s, (smod + (buf.empty() ? 0 : buf.back().second.second)) % mod}});
    for (auto p : qr[i]) {
      ans[p.second] = calc(p.first, i);
    }
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
}
