#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
namespace ModCalculator {
const int MOD = 1e9 + 7;
inline void Inc(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
inline void Dec(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
inline int Add(int x, int y) {
  Inc(x, y);
  return x;
}
inline int Sub(int x, int y) {
  Dec(x, y);
  return x;
}
inline int Mul(int x, int y) { return 1LL * x * y % MOD; }
inline int Ksm(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = Mul(ret, x);
    x = Mul(x, x);
  }
  return ret;
}
inline int Inv(int x) { return Ksm(x, MOD - 2); }
}  // namespace ModCalculator
using namespace ModCalculator;
int n, q, a[MAXN], ans[MAXN];
int pw2[MAXN], hsh[MAXN];
int f[MAXN], lef[MAXN], pre[MAXN];
long long blk[MAXN];
vector<int> ql[MAXN], qid[MAXN];
inline long long Sum(int l, int r) {
  return Sub(hsh[l], Mul(hsh[r + 1], pw2[r - l + 1]));
}
int getf(int x) { return (f[x] == x) ? x : f[x] = getf(f[x]); }
inline void Merge(int l, int r) {
  f[l] = r;
  lef[r] = lef[l];
  int len = l - lef[l];
  if (len > 30 && blk[r] > 0 || blk[l] + (blk[r] << len) > MOD) {
    blk[r] = MOD;
  } else {
    blk[r] = blk[l] + (blk[r] << len);
  }
}
void init() {
  read(n);
  read(q);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
  }
  for (int i = 1, l, r; i <= q; ++i) {
    read(l);
    read(r);
    ql[r].push_back(l);
    qid[r].push_back(i);
  }
  for (int i = pw2[0] = 1; i <= n; ++i) {
    pw2[i] = Add(pw2[i - 1], pw2[i - 1]);
  }
  for (int i = n; i >= 1; --i) {
    if (a[i] >= 0)
      hsh[i] = Add(Mul(hsh[i + 1], 2), a[i]);
    else
      hsh[i] = Sub(Mul(hsh[i + 1], 2), -a[i]);
  }
}
void solve() {
  for (int i = 1; i <= n; ++i) {
    f[i] = i;
    lef[i] = i - 1;
    blk[i] = a[i];
    while (blk[i] >= 0 && lef[i]) {
      Merge(lef[i], i);
    }
    pre[i] = Add(pre[lef[i]], Mul(Sum(lef[i] + 1, i), 2));
    for (int j = 0, sz = ql[i].size(); j < sz; ++j) {
      int pos = getf(ql[i][j]);
      ans[qid[i][j]] = Add(Sum(ql[i][j], pos), Sub(pre[i], pre[pos]));
    }
  }
  for (int i = 1; i <= q; ++i) {
    printf("%d\n", ans[i]);
  }
}
int main() {
  init();
  solve();
  return 0;
}
