#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << " = " << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << " = " << h << ", ";
  _dbg(sdbg + 1, a...);
}
const int maxn = (1e6) + 7;
const int maxk = 20;
const int inf = (1e9) + 7;
const long long LLinf = ((long long)1e18) + 7LL;
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long mod2 = 2LL * mod;
const int pot = 1 << 20;
long long tree[2 * pot + 7];
long long tab[maxn];
vector<pair<int, int> > wek[maxn];
long long odp[maxn];
set<int> zb;
long long pref[maxn];
long long wyk[maxn];
long long odw[maxn];
void zmien(long long &a) {
  if (a >= mod2) {
    a %= mod;
    a += mod2;
  } else {
    if (a <= -mod2) {
      a %= mod;
      a -= mod2;
    } else
      a %= mod2;
  }
}
long long suma(int l, int p) {
  long long res = 0;
  l += pot;
  p += pot;
  while (l <= p) {
    if (l & 1) res += tree[l];
    if (!(p & 1)) res += tree[p];
    l = (l + 1) / 2;
    p = (p - 1) / 2;
  }
  zmien(res);
  return res;
}
void ustaw(int x, long long val) {
  zmien(val);
  x += pot;
  tree[x] = val;
  while (x > 1) {
    x /= 2;
    tree[x] = tree[2 * x] + tree[2 * x + 1];
    zmien(tree[x]);
  }
}
void dorzuc(long long x, int pos) {
  if (x < 0 || ((int)(zb).size()) == 0) {
    zb.insert(pos);
    ustaw(pos, x);
    return;
  }
  auto it = zb.end();
  it--;
  long long cn = suma((*it), (*it));
  long long cnt = cn;
  ustaw((*it), 0LL);
  int num = (*it);
  cnt += wyk[pos - num] * x;
  zb.erase(it);
  zmien(cnt);
  if ((x > 0LL && pos - num > 30)) cnt = (cnt % mod2) + mod2;
  dorzuc(cnt, num);
}
int rob(long long a) { return ((a % mod) + mod) % mod; }
int licz(int a, int b) {
  long long cur = (pref[b] - pref[a - 1]) % mod;
  cur *= odw[a];
  return ((cur % mod) + mod) % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  wyk[0] = 1LL;
  odw[0] = 1LL;
  for (int i = 1; i <= n; i++) {
    wyk[i] = (2LL * wyk[i - 1]) % mod;
    odw[i] = (odw[i - 1] * (long long)(mod + 1) / 2LL) % mod;
    cin >> tab[i];
    pref[i] = (pref[i - 1] + wyk[i] * tab[i]) % mod;
    pref[i] = ((pref[i] + mod) % mod);
  }
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    wek[b].push_back({a, i});
  }
  for (int i = 1; i <= n; i++) {
    dorzuc(2LL * tab[i], i);
    assert(((int)(zb).size()) > 0);
    for (auto s : wek[i]) {
      odp[s.second] += suma(s.first + 1, i);
      auto it = zb.upper_bound(s.first);
      assert(it != zb.begin());
      if (it == zb.end())
        odp[s.second] += licz(s.first, i);
      else
        odp[s.second] += licz(s.first, (*it) - 1);
    }
  }
  for (int i = 0; i < q; i++) cout << rob(odp[i]) << "\n";
  return 0;
}
