#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e5 + 100, mod = 1e9 + 7;
long long pw[maxN + 1], pre[maxN + 1];
long long pa[maxN + 1], ans[maxN + 1];
long long a[maxN + 1], sum[maxN + 1];
long long h[maxN + 1], n, m, s[maxN + 1];
vector<pair<long long, long long> > num[maxN + 1];
inline long long read() {
  long long num = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    num = (num << 3ll) + (num << 1ll) + (ch ^ 48), ch = getchar();
  return num * f;
}
inline long long find(long long x) {
  return pa[x] == x ? x : pa[x] = find(pa[x]);
}
inline void merge(long long x, long long y) {
  if ((x - pre[x] > 31 && sum[y] > 0) ||
      sum[x] + (sum[y] << (x - pre[x])) > mod)
    sum[y] = mod;
  else
    sum[y] = sum[x] + (sum[y] << (x - pre[x]));
  pa[x] = y;
  pre[y] = pre[x];
}
inline long long query(long long x, long long y) {
  long long ans = h[x] - h[y + 1] * pw[y - x + 1] % mod;
  return (ans + mod) % mod;
}
int main() {
  n = read(), m = read();
  pw[0] = 1;
  for (long long i = 1; i <= n; i++)
    pre[i] = i - 1, a[i] = sum[i] = read(), pa[i] = i,
    pw[i] = pw[i - 1] * 2 % mod;
  for (long long i = n; i >= 1; i--) h[i] = (h[i + 1] * 2 + a[i]) % mod;
  for (long long i = 1; i <= m; i++) {
    long long l = read(), r = read();
    num[r].push_back(make_pair(l, i));
  }
  for (long long 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) % mod;
    for (long long j = 0; j < num[i].size(); j++) {
      pair<long long, long long> it = num[i][j];
      long long x = find(it.first);
      ans[it.second] = (s[i] - s[x] + query(it.first, x)) % mod;
    }
  }
  for (long long i = 1; i <= m; i++) printf("%lld\n", (ans[i] + mod) % mod);
  return 0;
}
