#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
const int N = 100005;
int n, Q, ans[N];
int a[N], P[N], s[N];
int f[N], pre[N], sp[N];
int sum[N];
vector<pair<int, int> > vQ[N];
int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
void merge(int x, int y) {
  if (x - pre[x] > 31 && sum[y] > 0)
    sum[y] = mo;
  else if (sum[x] + (1ll << (x - pre[x])) * sum[y] > mo)
    sum[y] = mo;
  else
    sum[y] = sum[x] + (1ll << (x - pre[x])) * sum[y];
  f[x] = f[y];
  pre[y] = pre[x];
}
int ask(int x, int y) {
  return (s[x] + mo - 1ll * s[y + 1] * P[y - x + 1] % mo) % mo;
}
int main() {
  P[0] = 1;
  scanf("%d%d", &n, &Q);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
  for (int i = (int)(1); i <= (int)(n); i++) f[i] = i, pre[i] = i - 1;
  for (int i = (int)(1); i <= (int)(n); i++) P[i] = 2ll * P[i - 1] % mo;
  for (int i = (int)(n); i >= (int)(1); i--)
    s[i] = (2ll * s[i + 1] + a[i]) % mo;
  for (int i = (int)(1); i <= (int)(Q); i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    vQ[r].push_back(pair<int, int>(l, i));
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    sum[i] = a[i];
    for (; pre[i] && sum[i] >= 0; merge(pre[i], i))
      ;
    sp[i] = (sp[pre[i]] + 2ll * ask(pre[i] + 1, i)) % mo;
    for (auto j : vQ[i]) {
      int a = j.first, b = get(a);
      ans[j.second] = (1ll * sp[i] - sp[b] + mo + 1ll * ask(a, b)) % mo;
    }
  }
  for (int i = (int)(1); i <= (int)(Q); i++)
    printf("%d\n", (ans[i] % mo + mo) % mo);
}
