#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
const long long N = 1e5 + 5, mod = 1e9 + 7;
long long n, m, a[N], lg[N], b[N], f[N], c[N], sum[N], d[N], ans[N];
struct en {
  long long l, r, id;
  bool operator<(const en &x) const { return r < x.r; }
} q[N];
long long zld(long long x) { return f[x] ? f[x] = zld(f[x]) : x; }
long long ji(long long x, long long y) {
  return (b[x] - b[y + 1] * lg[y - x + 1] % mod + mod) % mod;
}
void add(long long x, long long y) {
  f[x] = y;
  c[y] = c[x];
  if ((x - c[x] > 30 && sum[y] > 0) || (sum[x] + (sum[y] << x - c[x])) > mod)
    sum[y] = mod;
  else
    sum[y] = sum[x] + (sum[y] << x - c[x]);
}
signed main() {
  n = read(), m = read();
  lg[0] = 1;
  for (long long i = 1; i <= n; i++)
    sum[i] = a[i] = read(), lg[i] = (lg[i - 1] << 1) % mod, c[i] = i - 1;
  for (long long i = 1; i <= m; i++) q[i] = (en){read(), read(), i};
  for (long long i = n; i >= 1; i--)
    b[i] = ((b[i + 1] << 1) + a[i] + mod) % mod;
  sort(q + 1, q + m + 1);
  long long k = 1;
  for (long long i = 1; i <= n; i++) {
    while (sum[i] >= 0 && c[i]) add(c[i], i);
    d[i] = (d[c[i]] + (ji(c[i] + 1, i) << 1) % mod + mod) % mod;
    while (q[k].r == i) {
      long long x = zld(q[k].l);
      ans[q[k].id] = (d[i] - d[x] + ji(q[k].l, x) + mod) % mod;
      k++;
    }
  }
  for (long long i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
