#include <bits/stdc++.h>
using namespace std;
const long long N = 500010, mod = 1000000007;
long long n, m, a[N], sum[N], father[N], Prev[N], two[N], suf[N], val[N],
    ans[N];
struct node {
  long long l, r, id;
} ask[N];
inline long long read() {
  long long x = 0, tmp = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') tmp = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return tmp * x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  long long y = 10, len = 1;
  while (y <= x) {
    y = (y << 3) + (y << 1);
    len++;
  }
  while (len--) {
    y /= 10;
    putchar(x / y + 48);
    x %= y;
  }
}
long long searchfather(long long v) {
  return father[v] == v ? father[v] : father[v] = searchfather(father[v]);
}
inline void Union(long long x, long long y) {
  father[x] = y;
  Prev[y] = Prev[x];
  long long len = x - Prev[x];
  if (len > 30 && sum[y] > 0 || sum[x] + (sum[y] << len) > mod)
    sum[y] = mod;
  else
    sum[y] = sum[x] + (sum[y] << len);
}
inline long long query(long long l, long long r) {
  return (suf[l] - suf[r + 1] * two[r - l + 1] % mod + mod) % mod;
}
inline bool cmp(node a, node b) { return a.r < b.r; }
int main() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) {
    sum[i] = a[i] = read();
    Prev[i] = i - 1;
    father[i] = i;
  }
  for (long long i = n; i >= 1; i--)
    suf[i] = (suf[i + 1] * 2 + a[i] + mod) % mod;
  two[0] = 1;
  for (long long i = 1; i <= n; i++) two[i] = two[i - 1] * 2 % mod;
  for (long long i = 1; i <= m; i++) {
    ask[i].l = read();
    ask[i].r = read();
    ask[i].id = i;
  }
  sort(ask + 1, ask + 1 + m, cmp);
  long long j = 0;
  for (long long i = 1; i <= n; i++) {
    while (Prev[i] && sum[i] >= 0) Union(Prev[i], i);
    val[i] = (val[Prev[i]] + query(Prev[i] + 1, i) * 2) % mod;
    while (ask[j + 1].r == i) {
      long long x = searchfather(ask[++j].l);
      ans[ask[j].id] = (val[i] - val[x] + query(ask[j].l, x) + mod) % mod;
    }
  }
  for (long long i = 1; i <= m; i++) {
    write(ans[i]);
    putchar('\n');
  }
  return 0;
}
