#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long ret = 0;
  bool flg = 0;
  char ch = getchar();
  while (!isdigit(ch)) flg ^= !(ch ^ '-'), ch = getchar();
  while (isdigit(ch))
    ret = (ret << 1) + (ret << 3) + (ch ^ '0'), ch = getchar();
  return flg ? -ret : ret;
}
struct data {
  long long l, r, id;
  bool operator<(const data A) const { return r < A.r; }
} q[100010];
long long f[100010], sum[100010], pre[100010], cal[100010], powww[100010], n,
    a[100010], m, Ans[100010], block[100010];
long long find(long long x) { return f[x] == x ? x : f[x] = find(f[x]); }
void merge(long long x, long long y) {
  f[x] = f[y], pre[y] = pre[x];
  if ((x - pre[x] > 31 && sum[y] > 0) ||
      sum[x] + (sum[y] << x - pre[x]) > 1000000007)
    sum[y] = 1000000007;
  else
    sum[y] = sum[x] + (sum[y] << x - pre[x]);
}
long long Ask(long long x, long long y) {
  return (cal[x] - cal[y + 1] * powww[y - x + 1] % 1000000007 + 1000000007) %
         1000000007;
}
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= n; i++)
    sum[i] = a[i] = read(), pre[i] = i - 1, f[i] = i;
  for (long long i = 1; i <= m; i++) q[i] = (data){read(), read(), i};
  powww[0] = 1;
  for (long long i = 1; i <= n; i++) powww[i] = powww[i - 1] * 2 % 1000000007;
  for (long long i = n; i >= 0; i--)
    cal[i] = (a[i] + (cal[i + 1] << 1) % 1000000007 + 1000000007) % 1000000007;
  sort(q + 1, q + m + 1);
  long long now = 1;
  for (long long i = 1; i <= n && now <= m; i++) {
    while (sum[i] >= 0 && pre[i] > 0) merge(pre[i], i);
    if (pre[i] != 0)
      block[i] = block[pre[i]] +
                 (cal[pre[i] + 1] -
                  cal[i + 1] * powww[i - pre[i]] % 1000000007 + 1000000007) %
                     1000000007 * 2 % 1000000007;
    else
      block[i] = (cal[pre[i] + 1] -
                  cal[i + 1] * powww[i - pre[i]] % 1000000007 + 1000000007) %
                 1000000007;
    while (q[now].r == i && now <= m) {
      long long pos = find(q[now].l);
      Ans[q[now].id] = block[i] - block[pos] + Ask(q[now].l, pos);
      now++;
    }
  }
  for (long long i = 1; i <= m; i++)
    printf("%lld\n", (Ans[i] + 1000000007) % 1000000007);
  return 0;
}
