#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, P = 1e9 + 7, i2 = (P + 1) >> 1;
int n, q, ans[N], f[N], s[N], g[N], ar[N], pw[N], su[N], iw[N];
long long a[N];
bool ov[N];
struct O {
  int l, i;
};
vector<O> p[N];
int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); }
int X(int x) {
  if (x >= P) x -= P;
  return x;
}
int main() {
  scanf("%d%d", &n, &q);
  pw[0] = iw[0] = 1;
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]), pw[i] = X(pw[i - 1] << 1),
                          iw[i] = 1ll * iw[i - 1] * i2 % P,
                          su[i] = X(su[i - 1] + 1ll * X(a[i] + P) * pw[i] % P);
  for (int l, r, i = 1; i <= q; i++) {
    scanf("%d%d", &l, &r);
    if (r == 1)
      ans[i] = X(a[1] + P);
    else
      p[r].push_back((O){l, i});
  }
  s[1] = g[1] = X(a[1] + P);
  f[1] = ar[1] = 1;
  for (int z, i = 2; i <= n; i++) {
    f[i] = ar[i] = i;
    g[i] = X((a[i] + a[i]) % P + P);
    s[i] = X(s[get(i - 1)] + g[i]);
    while (get(i) != 1) {
      int x = get(i);
      if (ov[x] || a[x] >= 0) {
        int y = get(x - 1);
        if (a[x]) {
          if (x - y >= 30)
            a[y] = ((a[y] + a[x] * pw[x - y] % P) % P + P) % P, ov[y] = 1;
          else
            a[y] += a[x] * pw[x - y];
        }
        if (ov[x] || a[y] >= 1e9) ov[y] = 1;
        if (ov[y]) a[y] = (a[y] % P + P) % P;
        f[x] = y;
        ar[y] = i;
        if (y == 1)
          g[y] = 1ll * su[i] * i2 % P;
        else
          g[y] = 1ll * X(su[i] - su[y - 1] + P) * iw[y - 1] % P;
        s[y] = X(g[y] + s[get(y - 1)]);
      } else
        break;
    }
    z = p[i].size();
    for (int j = 0, l, x, v; j < z; j++) {
      l = p[i][j].l;
      x = get(l);
      v = p[i][j].i;
      ans[v] = 1ll * X(su[ar[x]] - su[l - 1] + P) * iw[l] % P;
      ans[v] = X(ans[v] + X(s[get(i)] - s[x] + P));
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", X(ans[i] + P));
  return 0;
}
