#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Os")
const long long maxn = 1e5 + 10, maxm = 3e5 + 10, lg = 17, mod = 1e9 + 7,
                inf = 1e18;
long long n, q, a[maxn], L[maxn][lg + 1], second[maxn][lg + 1], f[maxn],
    p2[maxn], i2[maxn], rs[maxn];
long long get(long long l, long long r) {
  return (f[l + 1] - (f[r + 1] * p2[r - l] % mod) + mod) % mod;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  p2[0] = 1;
  for (int i = 1; i < maxn; i++) p2[i] = p2[i - 1] * 2 % mod;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n; i >= 1; i--) f[i] = (f[i + 1] * 2 + a[i] + mod) % mod;
  for (int i = 1; i <= n; i++) {
    long long x = a[i];
    L[i][0] = i - 1;
    bool first = 0;
    while (x >= 0 && L[i][0]) {
      long long len = L[i][0] - L[L[i][0]][0];
      if (x >= mod || rs[L[i][0]] >= mod || (x != 0 && len >= 31)) {
        first = 1;
        break;
      }
      x = x * p2[len] + rs[L[i][0]];
      L[i][0] = L[L[i][0]][0];
    }
    rs[i] = x;
    if (first) L[i][0] = 0, rs[i] = mod;
    second[i][0] = get(L[i][0], i);
    for (int j = 1; j <= lg; j++) {
      L[i][j] = L[L[i][j - 1]][j - 1];
      second[i][j] = (second[i][j - 1] + second[L[i][j - 1]][j - 1]) % mod;
    }
  }
  while (q--) {
    long long l, r;
    cin >> l >> r;
    long long rr = r, ans = 0;
    for (int j = lg; j >= 0; j--)
      if (L[rr][j] >= l) {
        (ans += 2 * second[rr][j]) %= mod;
        rr = L[rr][j];
      }
    (ans += get(l - 1, rr)) %= mod;
    cout << ans << '\n';
  }
  return 0;
}
