#include <bits/stdc++.h>
using namespace std;
long long getint() {
  long long summ = 0, f = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch) && ch != '-'; ch = getchar())
    ;
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  for (; isdigit(ch); ch = getchar())
    summ = (summ << 3) + (summ << 1) + ch - 48;
  return summ * f;
}
const long long N = 5e5, mod = 1e9 + 7;
long long n, m, a[N], fa[N], pw[N], pre[N], sum[N], suf[N], ans[N], S[N];
struct node {
  long long l, r, id;
} q[N];
inline bool cmp(node x, node y) { return x.r < y.r; }
void merge(long long x, long long y) {
  fa[x] = y;
  pre[y] = pre[x];
  long long len = x - pre[x];
  if (len > 30 && sum[y] > 0 || (sum[x] + (sum[y] << len) > mod))
    sum[y] = mod;
  else
    sum[y] = sum[x] + (sum[y] << len);
}
long long qu(long long l, long long r) {
  return (suf[l] - suf[r + 1] * pw[r - l + 1] % mod + mod) % mod;
}
long long getfa(long long x) { return fa[x] ? fa[x] = getfa(fa[x]) : x; }
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) a[i] = getint();
  for (long long i = 1; i <= m; i++) {
    q[i].l = getint();
    q[i].r = getint();
    q[i].id = i;
  }
  sort(q + 1, q + m + 1, cmp);
  for (long long i = 1; i <= n; i++) {
    pre[i] = i - 1;
    fa[i] = 0, sum[i] = a[i];
  }
  for (long long i = n; i >= 1; i--)
    suf[i] = ((suf[i + 1] << 1) + a[i] + mod) % mod;
  pw[0] = 1;
  for (long long i = 1; i <= n; i++) pw[i] = (pw[i - 1] * 2) % mod;
  long long j = 0;
  for (long long i = 1; i <= n; i++) {
    while (pre[i] && sum[i] >= 0) merge(pre[i], i);
    S[i] = (S[pre[i]] + (qu(pre[i] + 1, i) * 2)) % mod;
    while (q[j + 1].r == i) {
      long long x = getfa(q[++j].l);
      ans[q[j].id] = (S[i] - S[x] + qu(q[j].l, x) + mod) % mod;
    }
  }
  for (long long i = 1; i <= m; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
