#include <bits/stdc++.h>
namespace FastIO {
const int MAX_BUF_SIZE = 1 << 15;
char *l, *r, InBuffer[MAX_BUF_SIZE];
inline int GetCh() {
  if (l == r) {
    l = InBuffer;
    r = l + fread(InBuffer, 1, MAX_BUF_SIZE, stdin);
    if (l == r) return -1;
  }
  return *l++;
}
template <typename T>
inline void Read(T &x) {
  char c = GetCh();
  long long tp = 1;
  for (; c < 48 || c > 57; c = GetCh())
    if (c == '-') tp = -tp;
  for (x = 0; c > 47 && c < 58; c = GetCh()) x = (x << 3) + (x << 1) + (c ^ 48);
  x *= tp;
  return;
}
int R;
char OutBuffer[MAX_BUF_SIZE];
inline void Flush() {
  if (R) fwrite(OutBuffer, 1, R, stdout);
  R = 0;
  return;
}
inline void Pt(char Ch) {
  OutBuffer[R++] = Ch;
  if (R == MAX_BUF_SIZE) Flush();
  return;
}
inline void Write(int x) {
  int T[10], Cnt = 0;
  if (!x)
    T[++Cnt] = 0;
  else {
    while (x) {
      T[++Cnt] = x % 10;
      x /= 10;
    }
  }
  while (Cnt) Pt(T[Cnt] + '0'), --Cnt;
  return;
}
inline void Write(long long x) {
  int T[20], Cnt = 0;
  if (!x)
    T[++Cnt] = 0;
  else {
    while (x) {
      T[++Cnt] = x % 10;
      x /= 10;
    }
  }
  while (Cnt) Pt(T[Cnt] + '0'), --Cnt;
  return;
}
}  // namespace FastIO
const int Maxn = 500010;
const int INF = 1e9;
const int Mod = 1e9 + 7;
int n, q, a[Maxn];
int CompareS[Maxn], Father[Maxn], Suf[Maxn];
int Pw[Maxn], BS[Maxn], PS[Maxn];
std::vector<std::pair<int, int> > Query[Maxn];
int Ans[Maxn];
inline int Split(int x, int y) {
  return (BS[x] - 1LL * BS[y] * Pw[y - x] % Mod + Mod) % Mod;
}
int Get(int x) { return Father[x] == x ? x : Father[x] = Get(Father[x]); }
int main() {
  FastIO::Read(n);
  FastIO::Read(q);
  Pw[0] = 1;
  for (int i = 1; i <= n; ++i) Pw[i] = (Pw[i - 1] << 1) % Mod;
  for (int i = 1; i <= n; ++i) FastIO::Read(a[i]);
  for (int i = n; i >= 1; --i)
    BS[i] = (((BS[i + 1] << 1) % Mod + a[i]) % Mod + Mod) % Mod;
  for (int i = 1; i <= q; ++i) {
    static int x, y;
    FastIO::Read(x);
    FastIO::Read(y);
    Query[y].push_back(std::pair<int, int>(x, i));
  }
  for (int i = 1; i <= n; ++i) {
    Father[i] = i;
    Suf[i] = i;
  }
  for (int i = 1; i <= n; ++i) {
    CompareS[i] = a[i];
    int Rt = i - 1;
    while (Rt && CompareS[i] > 0) {
      Father[Get(i)] = Get(Rt);
      CompareS[i] =
          (1LL * Pw[Rt - Get(Rt) + 1] * CompareS[i] + 1LL * CompareS[Rt] >=
           1LL * INF)
              ? INF
              : Pw[Rt - Get(Rt) + 1] * CompareS[i] + CompareS[Rt];
      Rt = Get(i) - 1;
      Suf[Get(i)] = i;
    }
    PS[i] = (PS[Rt] + Split(Rt + 1, i + 1)) % Mod;
    for (std::vector<std::pair<int, int> >::iterator it = Query[i].begin();
         it != Query[i].end(); ++it) {
      int l = it->first;
      int r = Suf[Get(l)];
      Ans[it->second] =
          (2LL * (PS[i] - PS[r] + Mod) % Mod + Split(l, r + 1)) % Mod;
    }
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", Ans[i]);
  return 0;
}
