#include <bits/stdc++.h>
inline int getint() {
  int x = 0, p = 1;
  char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int N = 1e5 + 5;
int n, q, pw[N], res[N], s[N], a[N], par[N], pre[N], suf[N];
long long sum[N];
vector<pair<int, int> > vq[N];
inline int add(int x, int y) {
  x += y;
  return (x >= 1000000007) ? x - 1000000007 : x;
}
inline int sub(int x, int y) {
  x -= y;
  return (x < 0) ? x + 1000000007 : x;
}
inline int mul(int x, int y) {
  long long ans = 1ll * x * y;
  return ans % 1000000007;
}
int findset(int x) {
  if (par[x] == x) return x;
  return par[x] = findset(par[x]);
}
inline int qry(int l, int r) {
  return sub(suf[l], mul(suf[r + 1], pw[r - l + 1]));
}
inline void merge(int x, int y) {
  if ((x - pre[x] > 31 && sum[y] > 0) ||
      sum[x] + (sum[y] << (x - pre[x])) > 1000000007)
    sum[y] = 1000000007;
  else
    sum[y] = sum[x] + (sum[y] << (x - pre[x]));
  par[x] = par[y];
  pre[y] = pre[x];
}
int main() {
  n = getint();
  q = getint();
  for (int i = 1; i <= n; i++) sum[i] = a[i] = getint();
  for (int i = 1; i <= n; i++)
    if (a[i] < 0) a[i] += 1000000007;
  for (int i = 1; i <= n; i++) par[i] = i, pre[i] = i - 1;
  pw[0] = 1;
  for (int i = 1; i < N; i++) pw[i] = add(pw[i - 1], pw[i - 1]);
  for (int i = n; i >= 1; i--) suf[i] = add(add(suf[i + 1], suf[i + 1]), a[i]);
  for (int(i) = 0; (i) < (q); (i)++) {
    int l = getint(), r = getint();
    vq[r].push_back(make_pair(l, i));
  }
  for (int i = 1; i <= n; i++) {
    while (pre[i] && sum[i] >= 0) merge(pre[i], i);
    s[i] = add(s[pre[i]], mul(2, qry(pre[i] + 1, i)));
    for (int(j) = 0; (j) < (vq[i].size()); (j)++) {
      int x = vq[i][j].first, y = findset(x), id = vq[i][j].second;
      res[id] = add(sub(s[i], s[y]), qry(x, y));
    }
  }
  for (int(i) = 0; (i) < (q); (i)++) printf("%d\n", res[i]);
  return 0;
}
