#include <bits/stdc++.h>
const int N = 1e5, MOD = 1e9 + 7;
int n, m, a[N + 5], fa[N + 5], p2[N + 5], pre[N + 5], s[N + 5], val[N + 5],
    sum[N + 5], ans[N + 5];
std::vector<std::pair<int, int>> q[N + 5];
inline int Find(int x) { return fa[x] == x ? x : (fa[x] = Find(fa[x])); }
inline void Merge(int x, int f) {
  fa[x] = fa[f], pre[f] = pre[x];
  int len = x - pre[x];
  if ((len >= 30 && val[f] > 0) || val[x] + (1LL << len) * val[f] > MOD)
    val[f] = MOD;
  else
    val[f] = val[x] + (val[f] << len);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = p2[0] = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    val[i] = a[i], a[i] += MOD * (a[i] < 0);
    fa[i] = i, pre[i] = i - 1, p2[i] = 2LL * p2[i - 1] % MOD;
  }
  for (int i = n; i >= 1; --i) s[i] = (2LL * s[i + 1] % MOD + a[i]) % MOD;
  for (int i = 1, l, r; i <= m; ++i) {
    scanf("%d%d", &l, &r);
    q[r].push_back(std::make_pair(l, i));
  }
  for (int i = 1; i <= n; ++i) {
    while (pre[i] && val[i] >= 0) Merge(pre[i], i);
    sum[i] =
        (sum[pre[i]] +
         2LL * (s[pre[i] + 1] - 1LL * p2[i - pre[i]] * s[i + 1] % MOD + MOD) %
             MOD) %
        MOD;
    for (const std::pair<int, int> p : q[i]) {
      int x = Find(p.first);
      ans[p.second] =
          ((sum[i] - sum[x] + MOD) % MOD +
           (s[p.first] - 1LL * p2[x - p.first + 1] * s[x + 1] % MOD + MOD) %
               MOD) %
          MOD;
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
