#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
const long long inf = 1e9;
const long long N = 1000005;
const long long mod = 1000000007;
long long qpow(long long a, long long b = mod - 2) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
long long pw[N], ipw[N], upd_val;
long long a[N], pre[N], ans[N], n, m;
vector<pair<long long, long long> > qry[N];
long long vmod[N], val[N], sum[N], cnt[N], id[N], top;
void init() {
  pw[0] = ipw[0] = 1;
  for (register long long i = 1; i < N; i++) pw[i] = 1ll * pw[i - 1] * 2 % mod;
  ipw[1] = qpow(2);
  for (register long long i = 1; i < N; i++)
    ipw[i] = 1ll * ipw[i - 1] * ipw[1] % mod;
  for (register long long i = 1; i <= n; i++)
    pre[i] = (1ll * pre[i - 1] + a[i] * pw[i]) % mod;
}
void ins(long long x, long long y) {
  ++top;
  val[top] = x, vmod[top] = (x % mod + mod) % mod;
  sum[top] = (sum[top - 1] + vmod[top]) % mod;
  cnt[top] = 1, id[top] = y;
}
long long getans(long long x) {
  long long cur = upper_bound(id + 1, id + top + 1, x) - id - 1;
  return (2ll * (sum[top] - sum[cur] + mod) +
          ipw[x] * (pre[id[cur] + cnt[cur] - 1] - pre[x - 1] + mod) % mod) %
         mod;
}
signed main() {
  n = read(), m = read();
  for (register long long i = 1; i <= n; i++) a[i] = read();
  for (register long long i = 1; i <= m; i++) {
    long long x = read(), y = read();
    qry[y].push_back({x, i});
  }
  init();
  for (register long long i = 1; i <= n; i++) {
    ins(a[i], i);
    while (1) {
      if (top <= 1 || (top > 1 && val[top] < 0)) break;
      if (!val[top])
        upd_val = val[top - 1];
      else if (cnt[top - 1] > 31)
        upd_val = inf + 1;
      else
        upd_val = min(inf + 5, pw[cnt[top - 1]] * val[top] + val[top - 1]);
      ckmin(upd_val, inf + 1);
      val[top - 1] = upd_val;
      vmod[top - 1] =
          (vmod[top - 1] + pw[cnt[top - 1]] * vmod[top] % mod) % mod;
      sum[top - 1] = (sum[top - 2] + vmod[top - 1]) % mod;
      cnt[top - 1] += cnt[top];
      top--;
    }
    for (auto v : qry[i]) ans[v.second] = getans(v.first);
  }
  for (register long long i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
