#include <bits/stdc++.h>
const int MAXN = 5e5 + 10, MOD = 1e9 + 7;
int n, Q;
int QAQ[MAXN], fa[MAXN], pre[MAXN], a[MAXN], pow2[MAXN], suf[MAXN], ans[MAXN],
    sum[MAXN];
std::vector<std::pair<int, int> > v[MAXN];
inline void init(void) {
  pow2[0] = 1;
  for (int i = 1; i < MAXN; ++i) pow2[i] = (pow2[i - 1] << 1) % MOD;
  return;
}
int find(int first) {
  return first == fa[first] ? first : fa[first] = find(fa[first]);
}
inline void merge(int first, int second) {
  fa[first] = fa[second], pre[second] = pre[first];
  int len = first - pre[first];
  if (len >= 30 && QAQ[second] > 0 ||
      QAQ[first] + (1LL << len) * QAQ[second] >= MOD)
    QAQ[second] = MOD;
  else
    QAQ[second] = QAQ[first] + (1 << len) * QAQ[second];
  return;
}
inline int query(int L, int R) {
  return (suf[L] - 1LL * suf[R + 1] * pow2[R - L + 1] % MOD + MOD) % MOD;
}
int main(void) {
  scanf("%d%d", &n, &Q), init();
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), fa[i] = i, pre[i] = i - 1, QAQ[i] = a[i],
                        a[i] = (a[i] + MOD) % MOD;
  for (int i = n; i; --i) suf[i] = (2LL * suf[i + 1] + a[i]) % MOD;
  for (int i = 1, L, R; i <= Q; ++i)
    scanf("%d%d", &L, &R), v[R].push_back(std::pair<int, int>(L, i));
  for (int i = 1; i <= n; ++i) {
    while (pre[i] && QAQ[i] >= 0) merge(pre[i], i);
    sum[i] = (sum[pre[i]] + 2LL * query(pre[i] + 1, i)) % MOD;
    int sz = v[i].size();
    for (int j = 0; j < sz; ++j) {
      int rib = find(v[i][j].first);
      ans[v[i][j].second] =
          ((sum[i] - sum[rib] + query(v[i][j].first, rib)) % MOD + MOD) % MOD;
    }
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}
