#include <bits/stdc++.h>
using namespace std;
const long long P = 1000000007;
const long long inv = 500000004;
const int maxn = 100010;
int n, m;
int f[maxn], pre[maxn];
long long v[maxn], s[maxn], sum[maxn], ans[maxn], pw[maxn], sp[maxn];
vector<pair<int, int> > q[maxn];
vector<pair<int, int> >::iterator it;
int find(int x) { return (f[x] == x) ? x : (f[x] = find(f[x])); }
inline void merge(int a, int b) {
  if ((a - pre[a] > 31 && sum[b] > 0) || sum[a] + (sum[b] << (a - pre[a])) > P)
    sum[b] = P;
  else
    sum[b] = sum[a] + (sum[b] << (a - pre[a]));
  f[a] = f[b], pre[b] = pre[a];
}
inline long long query(int a, int b) {
  return (s[a] - s[b + 1] * pw[b - a + 1] % P + P) % P;
}
int main() {
  scanf("%d%d", &n, &m);
  int i, a, b;
  for (pw[0] = i = 1; i <= n; i++)
    f[i] = i, pre[i] = i - 1, scanf("%lld", &v[i]),
    pw[i] = (pw[i - 1] << 1) % P;
  for (i = n; i >= 1; i--) s[i] = ((s[i + 1] << 1) + v[i] + P) % P;
  for (i = 1; i <= m; i++)
    scanf("%d%d", &a, &b), q[b].push_back(make_pair(a, i));
  for (i = 1; i <= n; i++) {
    sum[i] = v[i];
    while (pre[i] && sum[i] >= 0) merge(pre[i], i);
    sp[i] = (sp[pre[i]] + (query(pre[i] + 1, i) << 1)) % P;
    for (it = q[i].begin(); it != q[i].end(); it++) {
      a = (*it).first, b = find(a);
      ans[(*it).second] = (sp[i] - sp[b] + query(a, b) + P) % P;
    }
  }
  for (i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
