#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int res = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    res = (res << 1) + (res << 3) + (ch ^ 48);
    ch = getchar();
  }
  return res * f;
}
const int N = 5e5 + 5;
int fa[N], pre[N];
int get(int x) { return fa[x] ? fa[x] = get(fa[x]) : x; }
long long sum[N];
inline void merge(int x, int y) {
  fa[x] = y;
  pre[y] = pre[x];
  int len = x - pre[x];
  if (len > 30 && sum[y] > 0 || (sum[x] + (sum[y] << len)) > 1000000007)
    sum[y] = 1000000007;
  else
    sum[y] = sum[x] + (sum[y] << len);
}
long long suf[N], pw[N], S[N], ans[N];
inline long long query(int l, int r) {
  return (suf[l] - suf[r + 1] * pw[r - l + 1] % 1000000007 + 1000000007) %
         1000000007;
}
int n, q;
struct Q {
  int l, r, id;
  Q() {}
  Q(int _l, int _r, int _id) : l(_l), r(_r), id(_id) {}
  inline bool operator<(const Q &rhs) const { return r < rhs.r; }
} ask[N];
long long a[N];
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);
  for (int i = 1; i <= n; i++) pre[i] = i - 1, fa[i] = 0, sum[i] = a[i];
  for (int i = n; i; i--)
    suf[i] = ((suf[i + 1] << 1) + a[i] + 1000000007) % 1000000007;
  pw[0] = 1;
  for (int i = 1; i <= n; i++) pw[i] = (pw[i - 1] << 1) % 1000000007;
  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) << 1)) % 1000000007;
    while (ask[j + 1].r == i) {
      int x = get(ask[++j].l);
      ans[ask[j].id] =
          (S[i] - S[x] + query(ask[j].l, x) + 1000000007) % 1000000007;
    }
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}
