#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long MX = 2000000000LL;
long long n, m, x, y, sum[600000 << 2], a[600000], nxt[600000], lst[600000],
    ans[600000], tail;
vector<pair<long long, long long> > vec[600000];
struct tag {
  long long x, y;
  tag(long long x = 0, long long y = 0) : x(x), y(y) {}
  tag operator*(const tag &p) const { return tag(x * p.x, x * p.y + y); }
  tag operator^(const tag &p) const {
    return tag(x * p.x % mod, (x * p.y + y) % mod);
  }
} seg[600000 << 2];
void add(long long x, long long l, long long r, long long L, long long R,
         long long s) {
  if (l >= L && r <= R) {
    sum[x] = (sum[x] + s) % mod;
    return;
  }
  long long mid = (l + r) >> 1;
  if (L <= mid) add((x << 1), l, mid, L, R, s);
  if (R > mid) add((x << 1 | 1), mid + 1, r, L, R, s);
}
long long qry(long long x, long long l, long long r, long long k) {
  if (l == r) return sum[x];
  long long mid = (l + r) >> 1, ret = 0;
  if (k <= mid)
    ret = qry((x << 1), l, mid, k);
  else
    ret = qry((x << 1 | 1), mid + 1, r, k);
  return (ret + sum[x]) % mod;
}
void psd(long long x, long long l) {
  if (l >= nxt[tail]) {
    seg[(x << 1)] = seg[x] ^ seg[(x << 1)];
    seg[(x << 1 | 1)] = seg[x] ^ seg[(x << 1 | 1)];
  } else {
    seg[(x << 1)] = seg[x] * seg[(x << 1)];
    seg[(x << 1 | 1)] = seg[x] * seg[(x << 1 | 1)];
  }
  seg[x] = tag(1, 0);
}
void mdf(long long x, long long l, long long r, long long L, long long R,
         tag k) {
  if (l >= L && r <= R) {
    if (l >= nxt[tail]) {
      seg[x] = k ^ seg[x];
    } else {
      seg[x] = k * seg[x];
    }
    return;
  }
  psd(x, l);
  long long mid = (l + r) >> 1;
  if (L <= mid) mdf((x << 1), l, mid, L, R, k);
  if (R > mid) mdf((x << 1 | 1), mid + 1, r, L, R, k);
}
long long ask(long long x, long long l, long long r, long long k) {
  if (l == r) return seg[x].y;
  psd(x, l);
  long long mid = (l + r) >> 1;
  if (k <= mid) return ask((x << 1), l, mid, k);
  return ask((x << 1 | 1), mid + 1, r, k);
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; ++i) scanf("%lld", a + i);
  for (long long i = 1; i <= m; ++i) {
    scanf("%lld%lld", &x, &y);
    vec[x].push_back(make_pair(y, i));
  }
  tail = n;
  for (long long i = n; i; --i) {
    long long k = i + 1;
    for (; k <= tail; k = nxt[k]) {
      long long tmp = ask(1, 1, n, k);
      if (tmp < 0) {
        add(1, 1, n, k, nxt[k] - 1, tmp % mod * 2 % mod);
        mdf(1, 1, n, k, nxt[k] - 1, tag());
        nxt[i + 1] = nxt[k];
        lst[nxt[i + 1]] = i + 1;
        if (k == tail) tail = i + 1;
      } else
        break;
    }
    while (tail >= i) {
      long long tmp = ask(1, 1, n, tail);
      if (tmp >= MX)
        tail = lst[tail];
      else
        break;
    }
    nxt[i] = i + 1;
    lst[i + 1] = i;
    mdf(1, 1, n, i, nxt[tail] - 1, tag(2, a[i]));
    if (nxt[tail] <= n) mdf(1, 1, n, nxt[tail], n, tag(2, a[i]));
    for (long long j = 0; j < (long long)vec[i].size(); ++j) {
      long long x = vec[i][j].first, y = vec[i][j].second;
      ans[y] = ask(1, 1, n, x) + qry(1, 1, n, x);
    }
  }
  for (long long i = 1; i <= m; ++i)
    printf("%lld\n", (ans[i] % mod + mod) % mod);
  return 0;
}
