#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch;
  int sig = 1;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') sig = -1;
  int x = ch - '0';
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    x = x * 10 + ch - '0';
  return x * sig;
}
void write(long long x) {
  if (!x) {
    puts("0");
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  char ch[20];
  int tot = 0;
  for (; x; x /= 10) ch[++tot] = x % 10;
  for (int i = tot; i >= 1; i--) putchar(ch[i] + '0');
  puts("");
}
const int N = 1e5 + 5, Mo = 1e9 + 7;
struct que {
  int l, r, id;
} ask[N];
bool cmp(que x, que y) { return x.r < y.r; }
int pwr(int x, int y) {
  int z = 1;
  for (; y; y >>= 1, x = (long long)x * x % Mo)
    if (y & 1) z = (long long)z * x % Mo;
  return z;
}
int n, q, pre[N], fa[N], a[N];
long long sum[N], S[N], an[N], suf[N], two[N];
int get(int x) { return (fa[x] != x) ? fa[x] = get(fa[x]) : x; }
void merge(int x, int y) {
  fa[x] = fa[y];
  pre[y] = pre[x];
  int len = x - pre[x];
  if (len > 30 && sum[y] > 0 || sum[x] + (sum[y] << len) > Mo)
    sum[y] = Mo;
  else
    sum[y] = sum[x] + (sum[y] << len);
}
long long query(int l, int r) {
  return (suf[l] - suf[r + 1] * two[r - l + 1] % Mo + Mo) % Mo;
}
int main() {
  n = read();
  q = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= q; i++)
    ask[i].l = read(), ask[i].r = read(), ask[i].id = i;
  sort(ask + 1, ask + q + 1, cmp);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    pre[i] = i - 1;
    sum[i] = a[i];
  }
  for (int i = n; i >= 1; i--) suf[i] = (suf[i + 1] * 2 + a[i] + Mo) % Mo;
  two[0] = 1;
  for (int i = 1; i <= n; i++) two[i] = two[i - 1] * 2 % Mo;
  int j = 0;
  for (int i = 1; i <= n; i++) {
    while (pre[i] && sum[i] >= 0) merge(pre[i], i);
    S[i] = (S[pre[i]] + query(pre[i] + 1, i) * 2) % Mo;
    while (ask[j + 1].r == i) {
      int x = get(ask[++j].l);
      an[ask[j].id] = (S[i] - S[x] + query(ask[j].l, x) + Mo) % Mo;
    }
  }
  for (int i = 1; i <= q; i++) write(an[i]);
  return 0;
}
