#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2000000000;
const int maxn = 100010;
const int M1 = 1000000000 + 7;
const int M2 = 1000000000 + 9;
const int maxnlg = 20;
int N, Q, A[maxn], nxt[maxn];
pair<int, int> sp[maxnlg][maxn];
struct DS {
  int ps[maxn], pow2[maxn], M;
  void build(int *A, int m) {
    M = m;
    pow2[0] = 1;
    for (int i = 0; i < N; ++i) pow2[i + 1] = pow2[i] * 2 % M;
    ps[N] = 0;
    for (int i = (N)-1; i >= 0; --i)
      ps[i] = (1LL * ps[i + 1] * 2 + A[i] + M) % M;
  }
  int get(int l, int r) {
    return (ps[l] - 1LL * ps[r] * pow2[r - l] % M + M) % M;
  }
} ps1, ps2;
const int NEG = 0, BIG = 1, GOOD = 2;
int state(int l, int r) {
  int v1 = ps1.get(l, r);
  int v2 = ps2.get(l, r);
  if (v1 - ps1.M == v2 - ps2.M)
    return NEG;
  else if (v1 != v2)
    return BIG;
  else
    return GOOD;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> N >> Q;
  for (int i = 0; i < N; ++i) cin >> A[i];
  ps1.build(A, M1);
  ps2.build(A, M2);
  for (int i = 1; i < N + 1; ++i) {
    nxt[i] = i - 1;
    while (nxt[i] && state(nxt[i], i) == GOOD) nxt[i] = nxt[nxt[i]];
    if (state(nxt[i], i) == BIG) nxt[i] = 0;
    sp[0][i] = {nxt[i], ps1.get(nxt[i], i)};
  }
  for (int i = 0; i < maxnlg - 1; ++i)
    for (int j = 1; j < N + 1; ++j) {
      pair<int, int> a = sp[i][j];
      sp[i + 1][j].first = sp[i][a.first].first;
      sp[i + 1][j].second = (a.second + sp[i][a.first].second) % M1;
    }
  for (int qi = 0; qi < Q; ++qi) {
    int l, r;
    cin >> l >> r;
    int s = 0;
    for (int i = (maxnlg)-1; i >= 0; --i) {
      if (sp[i][r].first >= l) {
        s = (s + sp[i][r].second) % M1;
        r = sp[i][r].first;
      }
    }
    s = (1LL * s * 2 + ps1.get(l - 1, r)) % M1;
    cout << s << '\n';
  }
}
