#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mo = 1000000007;
inline int read() {
  register int x = 0, w = 1, ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') w = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  return w * x;
}
int n, m;
int a[maxn], b[maxn], c[maxn], d[maxn], pw[maxn], fa[maxn], ans[maxn];
long long sum[maxn];
struct node {
  int l, r, id;
  inline bool operator<(const node& rhs) const { return r < rhs.r; }
} q[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int calc(int x, int y) {
  return (b[x] - 1ll * b[y + 1] * pw[y - x + 1] % mo + mo) % mo;
}
void merge(int x, int y) {
  fa[x] = y;
  c[y] = c[x];
  if ((x - c[x] > 30 && sum[y] > 0) ||
      (1ll * sum[x] + (sum[y] << (x - c[x]))) > mo)
    sum[y] = mo;
  else
    sum[y] = sum[x] + (sum[y] << (x - c[x]));
}
int main() {
  n = read(), m = read();
  pw[0] = 1;
  for (int i = 1; i <= n; i++) a[i] = sum[i] = read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) pw[i] = (pw[i - 1] << 1) % mo, c[i] = i - 1;
  for (int i = 1; i <= m; i++) q[i] = (node){read(), read(), i};
  for (int i = n; i >= 1; i--) b[i] = (1ll * (b[i + 1] << 1) + a[i] + mo) % mo;
  sort(q + 1, q + m + 1);
  for (int i = 1, k = 1; i <= n; i++) {
    while (sum[i] >= 0 && c[i]) merge(c[i], i);
    d[i] = (1ll * d[c[i]] + (calc(c[i] + 1, i) << 1) % mo + mo) % mo;
    while (q[k].r == i) {
      int x = find(q[k].l);
      ans[q[k].id] = (1ll * d[i] - d[x] + calc(q[k].l, x) + 1ll * mo) % mo;
      k++;
    }
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
}
