#include <bits/stdc++.h>
const int MX = 40;
const int N = 100010;
const int M = 100010;
const long long MOD = 1e9 + 7;
const long long maxn = 1e9 + 2;
using namespace std;
int n, m;
int fa[N], len[N];
long long a[N], ans[M], num[N], sum[N], hlp[N], g[N];
int Q[N], top = 0;
long long KSM(long long x, int y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % MOD;
    x = x * x % MOD;
    y /= 2;
  }
  return res;
}
long long add(long long x, long long y) {
  return ((x % MOD + y % MOD) % MOD + MOD) % MOD;
}
long long dec(long long x, long long y) {
  return ((x % MOD - y % MOD) % MOD + MOD) % MOD;
}
long long DIV(long long x, long long y) { return x * KSM(y, MOD - 2) % MOD; }
struct nn {
  int l, r, id;
} q[N];
int cmp(nn A, nn B) { return A.r < B.r; }
void READ() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
  sort(q + 1, q + m + 1, cmp);
}
void INIT() {
  g[0] = 1;
  for (int i = 1; i <= n; i++) g[i] = g[i - 1] * 2 % MOD;
  long long now = 1;
  hlp[0] = sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    hlp[i] = add(hlp[i - 1], a[i] * now % MOD);
    now = now * 2 % MOD;
  }
}
int GETFA(int x) {
  if (fa[x] != x) fa[x] = GETFA(fa[x]);
  return fa[x];
}
void INS(int pos) {
  long long val = a[pos], flp = a[pos];
  while (top >= 1 && flp > 0) {
    int now = Q[top];
    top--;
    fa[pos] = now;
    len[now] += len[pos];
    if (pos - now >= 30 || num[now] + flp * g[pos - now] > maxn)
      flp = maxn + 1;
    else
      flp = num[now] + flp * g[pos - now];
    num[now] = (num[now] + val * g[pos - now]) % MOD;
    sum[now] = add(sum[Q[top]], num[now]);
    val = num[now];
    pos = now;
  }
  Q[++top] = pos;
  num[pos] = val % MOD;
  sum[pos] = add(sum[Q[top - 1]], num[pos]);
}
long long GET(int pos) {
  int l = GETFA(pos), r = l + len[l] - 1;
  long long val = dec(sum[Q[top]], sum[l]);
  long long now = DIV(dec(hlp[r], hlp[pos - 1]), g[pos - 1]);
  return add(now, val * 2 % MOD);
}
void SOLVE() {
  int pos = 1;
  for (int i = 1; i <= n; i++) fa[i] = i, len[i] = 1;
  for (int i = 1; i <= n; i++) {
    INS(i);
    while (pos <= m && q[pos].r == i) ans[q[pos].id] = GET(q[pos].l), pos++;
  }
  for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
}
int main() {
  READ();
  INIT();
  SOLVE();
  return 0;
}
