#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5, Mod = 1e9 + 7, INF = 2e9;
char buf[1 << 12], *p1 = buf, *p2 = buf, nc;
int ny;
inline char gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 12, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int x = 0;
  ny = 1;
  while (nc = gc(), (nc < 48 || nc > 57) && nc != EOF)
    if (nc == 45) ny = -1;
  if (nc < 0) return nc;
  x = nc - 48;
  while (nc = gc(), 47 < nc && nc < 58 && nc != EOF)
    x = (x << 3) + (x << 1) + (nc ^ 48);
  return x * ny;
}
int n, q, a[MAXN], s[MAXN], F[MAXN], f[MAXN], len[MAXN], Fpow[MAXN], ps[MAXN],
    res[MAXN], has[MAXN];
vector<pair<int, int> > S[MAXN];
int gf(int x) { return f[x] == x ? x : f[x] = gf(f[x]); }
inline void Merge(int x, int y) {
  x = gf(x), y = gf(y);
  if (x == y) return;
  if ((len[x] > 30 && s[x] > 0) || (s[x] + (1ll * s[y] << len[x])) >= INF)
    s[x] = INF;
  else
    s[x] += s[y] << len[x];
  F[x] = (F[x] + 1ll * F[y] * Fpow[len[x]]) % Mod, len[x] += len[y], f[y] = x;
}
inline int Calc(int l, int r) {
  return (has[l] - 1ll * has[r + 1] * Fpow[r - l + 1] % Mod + Mod) % Mod;
}
int main() {
  n = read(), q = read(), Fpow[0] = 1;
  for (int i = 1; i <= n; ++i)
    s[i] = a[i] = read(), F[i] = (a[i] < 0 ? a[i] + Mod : a[i]), f[i] = i,
    len[i] = 1, Fpow[i] = (Fpow[i - 1] << 1) % Mod;
  for (int i = n; i >= 1; --i) has[i] = (has[i + 1] * 2ll + a[i] + Mod) % Mod;
  for (int i = 1; i <= q; ++i) {
    int l = read(), r = read();
    S[r].push_back(make_pair(l, i));
  }
  for (int i = 1; i <= n; ++i) {
    while (gf(i) > 1 && s[gf(i)] >= 0) Merge(gf(gf(i) - 1), gf(i));
    ps[gf(i)] = (ps[gf(gf(i) - 1)] + F[gf(i)]) % Mod;
    for (auto o : S[i])
      res[o.second] = ((ps[gf(i)] - ps[gf(o.first)] + Mod) * 2ll +
                       Calc(o.first, gf(o.first) + len[gf(o.first)] - 1)) %
                      Mod;
  }
  for (int i = 1; i <= q; ++i) cout << res[i] << '\n';
  return 0;
}
