#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int n, q;
long long sum[101010], s[101010];
long long v[101010], POW[101010], suf[101010];
int pre[101010], fa[101010], size[101010];
struct node {
  int id, x, y;
} ask[101010];
long long ans[101010];
bool cmp(node u, node w) { return u.y < w.y; }
int find(int x) {
  if (fa[x] == x) return x;
  fa[x] = find(fa[x]);
  return fa[x];
}
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  fa[x] = y;
  pre[y] = pre[x];
  int len = x - pre[x];
  if (len > 32 && sum[y] > 0 || sum[x] + (sum[y] << len) > mod)
    sum[y] = mod;
  else
    sum[y] = sum[x] + (sum[y] << len);
}
long long sol(int x, int y) {
  long long sss = suf[x] - suf[y + 1] * POW[y - x + 1] % mod;
  return (sss % mod + mod) % mod;
}
int main() {
  scanf("%d%d", &n, &q);
  POW[0] = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &v[i]);
    sum[i] = v[i];
    POW[i] = POW[i - 1] * 2 % mod;
    fa[i] = i;
    pre[i] = i - 1;
  }
  for (int i = n; i >= 1; --i) suf[i] = (v[i] + suf[i + 1] * 2) % mod;
  for (int i = 1; i <= q; ++i)
    scanf("%d%d", &ask[i].x, &ask[i].y), ask[i].id = i;
  sort(ask + 1, ask + 1 + q, cmp);
  int id = 1;
  for (int i = 1; i <= n; ++i) {
    while (pre[i] && sum[i] >= 0) merge(pre[i], i);
    s[i] = (s[pre[i]] + sol(pre[i] + 1, i) * 2) % mod;
    while (id <= q && ask[id].y == i) {
      int x = ask[id].x;
      ans[ask[id].id] = s[i] - s[find(x)] + sol(x, find(x));
      ++id;
    }
  }
  for (int i = 1; i <= q; ++i) printf("%lld\n", (ans[i] % mod + mod) % mod);
  return 0;
}
