#include <bits/stdc++.h>
using namespace std;
const int N = 500100, mod = 1000000007;
int fa[N], n, m, pw[N], a[N], bl[N], sum[N], val[N], suf[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int calc(int l, int r) {
  return (suf[l] - (long long)suf[r + 1] * pw[r - l + 1] % mod + mod) % mod;
}
void merge(int x, int y) {
  fa[x] = y;
  bl[y] = bl[x];
  if ((x - bl[x] > 30 && sum[y] > 0) ||
      (sum[x] + ((long long)sum[y] << (x - bl[x])) > mod))
    sum[y] = mod;
  else
    sum[y] = sum[x] + (sum[y] << (x - bl[x]));
}
int ans[N];
vector<pair<int, int> > vec[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pw[i] = pw[i - 1] * 2 % mod;
    sum[i] = a[i];
    bl[i] = i - 1;
    fa[i] = i;
  }
  for (int i = 1; i <= m; ++i) {
    int l, r;
    cin >> l >> r;
    vec[r].emplace_back(l, i);
  }
  for (int i = n; i; --i) suf[i] = (suf[i + 1] * 2ll + a[i] + mod) % mod;
  for (int i = 1; i <= n; ++i) {
    for (; sum[i] >= 0 && bl[i]; merge(bl[i], i))
      ;
    val[i] = (val[bl[i]] + calc(bl[i] + 1, i) * 2ll % mod) % mod;
    for (auto j : vec[i]) {
      int x = find(j.first);
      ans[j.second] = ((val[i] - val[x] + calc(j.first, x)) % mod + mod) % mod;
    }
  }
  for (int i = 1; i <= m; ++i) cout << ans[i] << '\n';
  return 0;
}
