#include <bits/stdc++.h>
inline long long read() {
  long long x = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || '9' < c; c = getchar())
    if (c == '-') f = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
inline void write(long long x) {
  static char buf[20];
  int len = 0;
  if (x < 0) putchar('-'), x = -x;
  for (; x; x /= 10) buf[len++] = x % 10 + '0';
  if (!len)
    putchar('0');
  else
    while (len) putchar(buf[--len]);
}
inline void writesp(long long x) {
  write(x);
  putchar(' ');
}
inline void writeln(long long x) {
  write(x);
  putchar('\n');
}
struct Query {
  int l, r, id;
} q[200010];
long long s[200010], inv[200010], power[200010];
int a[200010];
int pos[200010], len[200010];
long long cur[200010], sum[200010];
int ans[200010];
int n, m;
bool cmp(Query a, Query b) { return a.r < b.r; }
long long calc(int l, int r) {
  return (s[r] - s[l - 1] + 1000000007) * inv[l - 1] % 1000000007;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  s[0] = 0;
  inv[0] = power[0] = 1;
  for (int i = 1; i <= n; i++) {
    inv[i] = inv[i - 1] * ((1000000007 + 1) / 2) % 1000000007;
    power[i] = power[i - 1] * 2 % 1000000007;
    s[i] = (s[i - 1] + (a[i] * power[i - 1] % 1000000007) + 1000000007) %
           1000000007;
  }
  for (int i = 1; i <= m; i++) q[i].l = read(), q[i].r = read(), q[i].id = i;
  std::sort(q + 1, q + m + 1, cmp);
  int tot = 0, last = 1;
  for (int i = 1; i <= n; i++) {
    pos[++tot] = i;
    len[tot] = 1;
    cur[tot] = a[i];
    sum[tot] = (sum[tot - 1] + cur[tot] % 1000000007 + 1000000007) % 1000000007;
    while (tot > 1 && cur[tot] >= 0) {
      if ((len[tot - 1] > 30 && cur[tot] > 0) ||
          (cur[tot - 1] + (cur[tot] << len[tot - 1])) > 0x7fffffff)
        cur[tot - 1] = 0x7fffffff;
      else
        cur[tot - 1] = (cur[tot - 1] + (cur[tot] << len[tot - 1]));
      sum[tot - 1] = (sum[tot - 1] + (sum[tot] - sum[tot - 1] + 1000000007) *
                                         power[len[tot - 1]]) %
                     1000000007;
      len[tot - 1] += len[tot];
      --tot;
    }
    while (last <= m && q[last].r <= i) {
      int l = 1, r = tot;
      while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (pos[mid] <= q[last].l)
          l = mid;
        else
          r = mid - 1;
      }
      ans[q[last].id] = ((sum[tot] - sum[l] + 1000000007) * 2 +
                         calc(q[last].l, pos[l] + len[l] - 1)) %
                        1000000007;
      ++last;
    }
  }
  for (int i = 1; i <= m; i++) writeln(ans[i]);
  putchar('\n');
  return 0;
}
