#include <bits/stdc++.h>
using namespace std;
const int maxn = 100011, p = 1000000007;
int n, Q, a[maxn];
void init() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
}
int L[maxn], T[maxn], POW[maxn], C[maxn], GL[maxn][20], SL[maxn][20];
inline int Get(int a, int b) {
  return 1LL * (C[b] - C[a - 1]) * POW[a - 1] % p;
}
void preset() {
  L[0] = 0;
  L[1] = 1;
  T[1] = a[1];
  for (int i = 2; i <= n; ++i) {
    if (a[i] < 0) {
      L[i] = i;
      T[i] = a[i];
      continue;
    }
    int x = i - 1;
    long long tmp = a[i];
    while (x) {
      if (tmp <= -T[x] >> x - L[x] + 1 || L[x] == 1) {
        L[i] = L[x];
        T[i] = T[x] + (tmp << x - L[x] + 1);
        break;
      }
      if (tmp > (1LL << 32) - T[x] >> x - L[x] + 1)
        tmp = 2e9;
      else
        tmp = T[x] + (tmp << x - L[x] + 1);
      x = L[x] - 1;
    }
  }
  POW[0] = 1;
  for (int i = 1; i <= n; ++i) POW[i] = POW[i - 1] * (p / 2 + 1LL) % p;
  for (int i = 1, t = 2; i <= n; ++i, t = 2 * t % p)
    C[i] = (C[i - 1] + 1LL * a[i] * t) % p;
  static int v[maxn];
  for (int i = 1; i <= n; ++i) GL[i][0] = L[i], SL[i][0] = Get(L[i], i);
  for (int i = 1; i <= n; ++i)
    for (int j = 0; GL[i][j]; ++j)
      GL[i][j + 1] = GL[GL[i][j] - 1][j],
                SL[i][j + 1] = (SL[GL[i][j] - 1][j] + SL[i][j]) % p;
}
void work() {
  preset();
  for (int l, r; Q--;) {
    scanf("%d%d", &l, &r);
    long long ans = a[l++];
    for (int k = 19; k >= 0; --k)
      if (GL[r][k] >= l) ans += SL[r][k], r = GL[r][k] - 1;
    if (l <= r) ans += Get(l, r);
    printf("%d\n", (ans % p + p) % p);
  }
}
int main() {
  init();
  work();
  return 0;
}
