#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
int f[100005];
inline int find(int x) { return f[x] == x ? f[x] : f[x] = find(f[x]); }
int n, q;
int nx[100005], t[100005];
vector<pair<int, int> > vt[100005];
int Ans[100005];
int s[100005], S[100005], a[100005];
void merge(int x, int y) {
  int len = y - nx[y];
  if ((len > 30 && t[x] > 0) || (t[y] + ((long long)t[x] << len) > 1000000007))
    t[x] = 1000000007;
  else
    t[x] = t[y] + ((long long)t[x] << len);
  f[y] = f[x], nx[x] = nx[y];
}
inline int qpow(int x, int k) {
  int ans = 1;
  for (; k; k >>= 1, x = 1ll * x * x % 1000000007)
    if (k & 1) ans = 1ll * ans * x % 1000000007;
  return ans;
}
int query(int x, int y) {
  return (s[x] - 1ll * s[y + 1] * qpow(2, y - x + 1) % 1000000007 +
          1000000007) %
         1000000007;
}
int main() {
  n = rd();
  q = rd();
  for (int i = int(1); i <= (int)(n); i++) a[i] = rd(), f[i] = i, nx[i] = i - 1;
  for (int i = int(n); i >= (int)(1); i--)
    s[i] = ((long long)(s[i + 1] << 1) + a[i] + 1000000007) % 1000000007;
  for (int i = int(1); i <= (int)(q); i++) {
    int x = rd(), y = rd();
    vt[y].push_back(make_pair(x, i));
  }
  for (int i = int(1); i <= (int)(n); i++) {
    t[i] = a[i];
    while (nx[i] && t[i] > 0) merge(i, nx[i]);
    S[i] = (S[nx[i]] + 1ll * query(nx[i] + 1, i) * 2) % 1000000007;
    for (auto j : vt[i]) {
      Ans[j.second] = ((long long)S[i] - S[find(j.first)] + 1000000007 +
                       query(j.first, find(j.first))) %
                      1000000007;
    }
  }
  for (int i = int(1); i <= (int)(q); i++) wrt(Ans[i], '\n');
}
