#include <bits/stdc++.h>
using namespace std;
inline 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 << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : -x;
}
inline void print(long long x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x >= 10) print(x / 10);
  putchar((x % 10) | 48);
}
const long long mod = 1e9 + 7;
long long n, q;
long long a[100010], b[100010];
long long sum[100010];
long long pre[100010];
long long fa[100010], f[100010];
struct node {
  long long l, r, id;
  inline bool operator<(const node &x) const { return r < x.r; }
} Q[100010];
long long pw[100010];
long long ans[100010];
long long find(long long x) { return fa[x] == x ? fa[x] : fa[x] = find(fa[x]); }
inline long long cut(long long x, long long y) {
  return (b[x] - b[y + 1] * pw[y - x + 1] % mod + mod) % mod;
}
void add(long long x, long long y) {
  f[y] = f[x], fa[find(x)] = find(y);
  if ((x - f[x] > 30 && sum[y] > 0) || sum[x] + (sum[y] << x - f[x]) > mod)
    sum[y] = mod;
  else
    sum[y] = sum[x] + (sum[y] << x - f[x]);
}
signed main() {
  n = read(), q = read();
  pw[0] = 1;
  for (long long i = 1; i <= n; ++i) pw[i] = (pw[i - 1] << 1) % mod;
  for (long long i = 1; i <= n; ++i)
    sum[i] = a[i] = read(), fa[i] = i, f[i] = i - 1;
  for (long long i = n; i >= 1; --i) b[i] = (a[i] + b[i + 1] * 2ll) % mod;
  for (long long i = 1; i <= q; ++i)
    Q[i].l = read(), Q[i].r = read(), Q[i].id = i;
  sort(Q + 1, Q + q + 1);
  long long pos = 1;
  for (long long i = 1; i <= n; ++i) {
    while (sum[fa[i]] >= 0 && f[i]) add(f[i], fa[i]);
    pre[i] = (pre[f[i]] + (cut(f[i] + 1, i) * 2) % mod) % mod;
    while (pos <= q && Q[pos].r == i) {
      long long x = find(Q[pos].l);
      ans[Q[pos].id] = (pre[i] - pre[x] + cut(Q[pos].l, x) + mod) % mod;
      ++pos;
    }
  }
  for (long long i = 1; i <= q; ++i) {
    printf("%d\n", (ans[i] + mod) % mod);
  }
  return 0;
}
