#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 5e5 + 10;
long long n, m, a[maxn], fa[maxn], pre[maxn], Two[maxn], suf[maxn], blo[maxn];
long long sum[maxn], ans[maxn];
vector<pair<long long, long long> > que[maxn];
inline long long power(long long a, long long b) {
  long long res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) res = 1ll * res * a % mod;
  return res;
}
inline long long add(long long x) { return x >= mod ? x - mod : x; }
inline long long sub(long long x) { return x < 0 ? x + mod : x; }
inline long long Get(long long l, long long r) {
  return sub((suf[l] - 1ll * suf[r + 1] * Two[r - l + 1]) % mod);
}
inline long long ask(long long x) {
  if (fa[x] == x)
    return x;
  else
    return fa[x] = ask(fa[x]);
}
inline void merge(long long x, long long y) {
  fa[x] = fa[y];
  pre[y] = pre[x];
  long long dis = x - pre[x];
  if (blo[y] > 0 && dis >= 30)
    blo[y] = mod;
  else if ((blo[x] + ((1ll * blo[y]) << dis)) > mod)
    blo[y] = mod;
  else
    blo[y] = (blo[x] + ((1ll * blo[y]) << dis));
}
int main() {
  scanf("%lld%lld", &n, &m);
  Two[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    Two[i] = 2ll * Two[i - 1] % mod;
    fa[i] = i;
    pre[i] = i - 1;
    blo[i] = a[i];
    a[i] = sub(a[i]);
  }
  for (long long i = n; i >= 1; --i) suf[i] = add(2 * suf[i + 1] % mod + a[i]);
  for (long long i = 1, l, r; i <= m; ++i) {
    scanf("%lld%lld", &l, &r);
    que[r].push_back(make_pair(i, l));
  }
  for (long long i = 1; i <= n; ++i) {
    while (blo[i] >= 0 && pre[i] > 0) merge(pre[i], i);
    sum[i] = add(sum[pre[i]] + 2ll * Get(pre[i] + 1, i) % mod);
    for (long long j = 0; j < (long long)que[i].size(); ++j) {
      long long now = ask(que[i][j].second);
      ans[que[i][j].first] =
          add(sub(sum[i] - sum[now]) + Get(que[i][j].second, now));
    }
  }
  for (long long i = 1; i <= m; ++i) printf("%lld\n", ans[i]);
  return 0;
}
