#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long N = 5e5 + 10, mod = 1e9 + 7;
long long n, m, a[N], po[N], ipo[N], pre[N];
vector<long long> q[N], id[N];
long long rval[N], val[N], sum[N], cnt[N], beg[N], top;
long long ans[N];
template <class T>
inline void read(T &x) {
  x = 0;
  bool fl = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') fl = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  if (fl) x = -x;
}
template <class T>
inline T fpow(T x, T y, T p) {
  T r = 1;
  while (y) {
    if (y & 1) r = 1LL * r * x % p;
    x = 1LL * x * x % p;
    y >>= 1;
  }
  return r;
}
void init() {
  po[0] = 1;
  for (long long i = 1; i <= n; ++i) po[i] = 2 * po[i - 1] % mod;
  ipo[0] = 1;
  ipo[1] = fpow(2ll, mod - 2, mod);
  for (long long i = 2; i <= n; ++i) ipo[i] = ipo[i - 1] * ipo[1] % mod;
  for (long long i = 1, t = 2; i <= n; ++i, t = 2 * t % mod)
    pre[i] = (pre[i - 1] + a[i] * t % mod + mod) % mod;
}
void push(long long x, long long y) {
  val[++top] = x;
  rval[top] = (x + mod) % mod;
  sum[top] = (sum[top - 1] + rval[top]) % mod;
  cnt[top] = 1;
  beg[top] = y;
}
bool pop() {
  if (top <= 1) return false;
  if (val[top] < 0) return false;
  long long newval;
  if (val[top] == 0)
    newval = val[top - 1];
  else if (cnt[top - 1] > 31)
    newval = inf + 1;
  else if (po[cnt[top - 1]] * val[top] + val[top - 1] > inf)
    newval = inf + 1;
  else
    newval = po[cnt[top - 1]] * val[top] + val[top - 1];
  val[top - 1] = newval;
  rval[top - 1] = (rval[top - 1] + po[cnt[top - 1]] * rval[top] % mod) % mod;
  sum[top - 1] = (sum[top - 2] + rval[top - 1]) % mod;
  cnt[top - 1] += cnt[top];
  top--;
  return true;
}
long long solve_solve(long long x) {
  long long l = 1, r = top, mid, now;
  while (l <= r) {
    mid = l + r >> 1;
    if (beg[mid] <= x)
      now = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return (2 * (sum[top] - sum[now] + mod) +
          ipo[x] * (pre[beg[now] + cnt[now] - 1] - pre[x - 1] + mod) % mod) %
         mod;
}
void solve() {
  top = 0;
  for (long long i = 1; i <= n; ++i) {
    push(a[i], i);
    while (pop())
      ;
    for (long long j = 0, sz = q[i].size(); j < sz; ++j)
      ans[id[i][j]] = solve_solve(q[i][j]);
  }
}
signed main() {
  read(n);
  read(m);
  for (long long i = 1; i <= n; ++i) read(a[i]);
  for (long long i = 1; i <= m; ++i) {
    long long x, y;
    read(x);
    read(y);
    q[y].push_back(x);
    id[y].push_back(i);
  }
  init();
  solve();
  for (long long i = 1; i <= m; ++i) printf("%lld\n", ans[i]);
  return 0;
}
