#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int mod = 1e9 + 7;
int n, m, a[N], pre[N], inv2[N], f[N], sum[N], len[N], preans[N], out[N];
struct Query {
  int l, id;
  Query(int _l = 0, int _id = 0) {
    l = _l;
    id = _id;
  }
};
vector<Query> query[N];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
int calc(int l, int r) {
  return (long long)(pre[r] - pre[l - 1] + mod) * inv2[l - 1] % mod;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, two = 1; i <= n; ++i, two = two * 2 % mod) {
    scanf("%d", a + i);
    pre[i] = (pre[i - 1] + (long long)a[i] * two % mod + mod) % mod;
  }
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    query[r].push_back(Query(l, i));
  }
  inv2[0] = 1;
  for (int i = 1; i <= n; ++i)
    inv2[i] = (long long)inv2[i - 1] * (mod + 1) / 2 % mod;
  for (int i = 1; i <= n; ++i) {
    f[i] = i;
    len[i] = 1;
    sum[i] = a[i];
    while (find(i) > 1 && sum[find(i)] > 0) {
      int x = find(i);
      int y = find(x - 1);
      if (len[y] >= 30 || sum[y] + (((long long)sum[x]) << len[y]) > 1e9)
        sum[y] = 1e9;
      else
        sum[y] += sum[x] << len[y];
      len[y] += len[x];
      f[x] = y;
    }
    preans[find(i)] = (preans[find(find(i) - 1)] +
                       2ll * calc(find(i), find(i) + len[find(i)] - 1)) %
                      mod;
    for (auto q : query[i]) {
      int x = find(q.l);
      out[q.id] = (0ll + preans[find(i)] - preans[x] + mod +
                   calc(q.l, x + len[x] - 1)) %
                  mod;
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", out[i]);
  return 0;
}
