#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
const int N = 1e5;
const int mod = 1e9 + 7;
int n, q;
int pow2[N + 1];
int val[N + 1], fa[N + 1], sz[N + 1];
int sum1[N + 1], sum2[N + 1], suml[N + 1], sumr[N + 2];
vector<pair<int, int> > query[N + 1];
int ans[N + 1];
inline int gfa(int x) {
  if (fa[x] != x) fa[x] = gfa(fa[x]);
  return fa[x];
}
inline void merge(int x, int y) {
  fa[y] = x;
  if ((sz[x] > 30 && sum1[x] > 0) ||
      sum1[x] + ((1ll * sum1[y]) << sz[x]) >= 2e9)
    sum1[x] = 2e9;
  else
    sum1[x] = sum1[x] + ((1ll * sum1[y]) << sz[x]);
  sum2[x] = (sum2[x] + 1ll * sum2[y] * pow2[sz[x]] % mod) % mod;
  sz[x] += sz[y];
  return;
}
int main() {
  n = read();
  q = read();
  pow2[0] = 1;
  for (int i = 1; i <= n; i++) {
    sum1[i] = sum2[i] = val[i] = read();
    fa[i] = i;
    sz[i] = 1;
    pow2[i] = 2ll * pow2[i - 1] % mod;
  }
  for (int i = n; i >= 1; i--)
    sumr[i] = (2ll * sumr[i + 1] % mod + val[i] + mod) % mod;
  for (int i = 1; i <= q; i++) {
    int l = read(), r = read();
    query[r].push_back(make_pair(i, l));
  }
  for (int i = 1; i <= n; i++) {
    while (gfa(i) > 1 && sum1[gfa(i)] >= 0) merge(gfa(gfa(i) - 1), gfa(i));
    suml[gfa(i)] = (1ll * suml[gfa(gfa(i) - 1)] + sum2[gfa(i)] + mod) % mod;
    for (int j = 0; j < query[i].size(); j++) {
      int num = query[i][j].first, l = query[i][j].second,
          r = gfa(l) + sz[gfa(l)] - 1;
      ans[num] =
          (2ll * (1ll * suml[gfa(i)] - suml[gfa(l)] + mod) % mod +
           (1ll * sumr[l] - (1ll * sumr[r + 1] * pow2[r - l + 1] % mod) + mod) %
               mod +
           mod) %
          mod;
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
