#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, mo = 1e9 + 7;
int n, q, l, r;
int fa[20][N], s[N], a[N], b[N], _[N], ans;
void R(int &n) {
  char c;
  int fh = 1;
  for (n = 0; (c = getchar()) < '0' || c > '9';)
    if (c == '-') fh = -1;
  for (; c <= '9' && c >= '0'; c = getchar()) n = n * 10 + c - 48;
  n *= fh;
}
void P(int n) {
  if (!n) putchar('0');
  int j = 0;
  char o[30];
  for (; n; n /= 10) o[++j] = n % 10 + 48;
  for (; j;) putchar(o[j--]);
  putchar('\n');
}
int main() {
  R(n);
  R(q);
  for (int i = 1, _e = n; i <= _e; ++i) R(a[i]);
  for (int i = n, _e = 1; i >= _e; --i)
    b[i] = ((long long)b[i + 1] + a[i]) * 2 % mo;
  _[0] = 1;
  for (int i = 1, _e = n; i <= _e; ++i) _[i] = _[i - 1] * 2 % mo;
  for (int i = 1, _e = n; i <= _e; ++i)
    if (a[i] <= 0)
      fa[0][i] = i - 1;
    else {
      int j = i;
      long long o = a[i];
      for (; --j;) {
        o = o * 2 + a[j];
        if (o > 1e9) {
          j = 0;
          break;
        }
        if (o <= 0) break;
      }
      fa[0][i] = j - (o <= 0);
    }
  for (int i = 1, _e = 18; i <= _e; ++i)
    for (int j = 1, _e = n; j <= _e; ++j) fa[i][j] = fa[i - 1][fa[i - 1][j]];
  for (int i = 1, _e = n; i <= _e; ++i)
    s[i] = (s[fa[0][i]] + ((-(long long)b[i + 1] * _[(i) - (fa[0][i] + 1) + 1] +
                            b[fa[0][i] + 1]) %
                           mo)) %
           mo;
  for (; q--;) {
    R(l);
    R(r);
    if (l == r)
      P((a[l] + mo) % mo);
    else {
      ans = a[l] + s[r];
      ++l;
      for (int i = 18, _e = 0; i >= _e; --i)
        if (fa[i][r] >= l) r = fa[i][r];
      ans = (((long long)ans - s[r] +
              ((-(long long)b[r + 1] * _[(r) - (l) + 1] + b[l]) % mo)) %
                 mo +
             mo) %
            mo;
      P(ans);
    }
  }
}
