#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 1000000007;
int suf[maxn], sum[maxn], v[maxn], s[maxn];
int bin[maxn], pa[maxn], L[maxn], ans[maxn];
vector<pair<int, int> > q[maxn];
int n, m, l, r, sz;
void merge(int a, int b) {
  if (a - L[a] > 40 && sum[b] > 0 ||
      ((1ll * sum[b]) << (a - L[a] + 1)) + sum[a] > 2 * mod)
    sum[b] = 2 * mod;
  else
    sum[b] = (sum[b] << (a - L[a] + 1)) + sum[a];
  pa[a] = b;
  L[b] = L[a];
  v[b] = (v[a] + 1ll * bin[a - L[a] + 1] * v[b]) % mod;
}
int getpa(int x) { return pa[x] == x ? x : pa[x] = getpa(pa[x]); }
int query(int l, int r) {
  int ans = 0, t = getpa(l);
  ans = (s[r] + mod - s[t]) % mod;
  ans = (ans + suf[l] - 1ll * bin[t - l + 1] * suf[t + 1] % mod) % mod;
  return (ans % mod + mod) % mod;
}
int main() {
  scanf("%d%d", &n, &m);
  bin[0] = 1;
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &v[i]);
    bin[i] = 2 * bin[i - 1] % mod;
  }
  for (int i = (1); i <= (m); i++) {
    scanf("%d%d", &l, &r);
    q[r].push_back(make_pair(l, i));
  }
  for (int i = (n); i >= (1); i--) suf[i] = (2ll * suf[i + 1] + v[i]) % mod;
  for (int i = (1); i <= (n); i++) {
    pa[i] = i;
    sum[i] = v[i];
    L[i] = i;
    while (L[i] >= 2 && sum[i] >= 0) merge(L[i] - 1, i);
    s[i] = (s[L[i] - 1] + 2ll * v[i]) % mod;
    sz = q[i].size();
    for (int j = (0); j <= (sz - 1); j++)
      ans[q[i][j].second] = query(q[i][j].first, i);
  }
  for (int i = (1); i <= (m); i++) printf("%d ", ans[i]);
  return 0;
}
