#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int n = 0, f = 1;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') f = -1, c = getchar();
  for (; c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - 48;
  return n * f;
}
const int maxn = 1e5 + 5, mo = 1e9 + 7;
int i, j, n, q, a[maxn], ans[maxn], f[maxn];
int num, two[maxn], s[maxn], S[maxn], be[maxn], L, l[maxn];
long long p[maxn], now;
struct ar {
  int l, r, id;
} Q[maxn];
bool cmp(ar a, ar b) { return a.r < b.r; }
int find(int l, int r) {
  return ((s[l] - (long long)s[r + 1] * two[r - l + 1]) % mo + mo) % mo;
}
int get(int x) { return f[x] ? f[x] = get(f[x]) : x; }
int main() {
  n = read(), q = read();
  memset(f, 0, sizeof(f));
  two[0] = 1;
  for (i = 1; i <= n; i++) a[i] = read(), two[i] = two[i - 1] * 2 % mo;
  for (i = n; i >= 1; i--) s[i] = (s[i + 1] * 2 % mo + a[i]) % mo;
  for (i = 1; i <= q; i++) Q[i].l = read(), Q[i].r = read(), Q[i].id = i;
  sort(Q + 1, Q + 1 + q, cmp);
  j = 1;
  for (i = 1; i <= n; i++) {
    now = a[i], L = i;
    for (; num && now >= 0; num--) {
      int len = L - l[num];
      f[L] = l[num], L = l[num];
      if (!now)
        now = p[num];
      else {
        if (len > 31)
          now = mo;
        else
          now = (mo < p[num] + (now << len) ? mo : p[num] + (now << len));
      }
    }
    p[++num] = now, l[num] = L, be[L] = num,
    S[num] = (S[num - 1] + find(L, i) * 2 % mo) % mo;
    for (; Q[j].r == i; j++) {
      int x = be[get(Q[j].l)], r = x < num ? l[x + 1] - 1 : i;
      ans[Q[j].id] = ((S[num] - S[x] + find(Q[j].l, r)) % mo + mo) % mo;
    }
  }
  for (i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
