#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, ans, sum, x[100010], tot, mo = 1e9 + 7, bi[100010], an[100010];
long long inf = 2e9 + 7, bb[100010];
struct qu {
  int l, r, id;
} q[100010];
bool cmpl(qu a, qu b) { return a.l < b.l; }
bool cmpr(qu a, qu b) { return a.r < b.r; }
struct node {
  int c, v;
  long long w;
  node(int _c = 0, int _v = 0, long long _w = 0) {
    if (_v < 0) _v += mo;
    _w = min(_w, inf);
    c = _c, v = _v, w = _w;
  }
  node operator+(node const &a) const {
    return node(c + a.c, (v + (long long)bi[c] * a.v) % mo,
                min(inf, w + (long long)bb[c] * a.w));
  }
} d[100010], p[100010];
void add(int &a, int b) {
  if (b < 0) b += mo;
  a += b;
  if (a >= mo) a -= mo;
}
int main() {
  int i, s, a, b, j, k;
  scanf("%d%d", &n, &m);
  for (i = bb[0] = bi[0] = 1; i <= n; i++)
    bi[i] = (long long)bi[i - 1] * 2 % mo,
    bb[i] = min(inf, (long long)bb[i - 1] * 2);
  for (i = 1; i <= n; i++) scanf("%d", &x[i]);
  for (i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
  sort(q + 1, q + 1 + m, cmpl);
  j = sqrt(n + 1);
  for (k = s = 1; k <= n; k += j) {
    a = s;
    while (q[a].l < k + j && a <= m) a++;
    if (a == s) continue;
    sort(q + s, q + a, cmpr);
    tot = ans = 0;
    a = k + j;
    for (i = 1; i <= tot; i++) add(ans, (long long)2 * d[i].v % mo);
    while (q[s].l < k + j && s <= m) {
      if (q[s].r - q[s].l <= j + 5) {
        cnt = sum = 0;
        for (i = q[s].l; i <= q[s].r; i++) {
          if (x[i] < 0)
            p[++cnt] = node(1, x[i] % mo, x[i]);
          else {
            p[++cnt] = node(1, x[i] % mo, x[i]);
            while (cnt > 1 && p[cnt].w >= 0)
              p[cnt - 1] = p[cnt - 1] + p[cnt], cnt--;
          }
        }
        add(sum, p[1].v);
        for (i = 2; i <= cnt; i++) add(sum, (long long)2 * p[i].v % mo);
        an[q[s++].id] = sum;
        continue;
      }
      while (a <= q[s].r) {
        if (x[a] < 0)
          d[++tot] = node(1, x[a] % mo, x[a]),
          add(ans, (long long)2 * x[a] % mo);
        else {
          d[++tot] = node(1, x[a] % mo, x[a]);
          while (tot > 1 && d[tot].w >= 0) {
            add(ans, mo - (long long)2 * d[tot - 1].v % mo);
            d[tot - 1] = d[tot - 1] + d[tot], tot--;
          }
          add(ans, (long long)2 * d[tot].v % mo);
        }
        a++;
      }
      cnt = 0;
      sum = ans;
      for (i = q[s].l; i < j + k; i++) {
        if (x[i] < 0)
          p[++cnt] = node(1, x[i] % mo, x[i]);
        else {
          p[++cnt] = node(1, x[i] % mo, x[i]);
          while (cnt > 1 && p[cnt].w >= 0)
            p[cnt - 1] = p[cnt - 1] + p[cnt], cnt--;
        }
      }
      if (tot && d[1].w >= 0) {
        add(sum, mo - (long long)2 * d[1].v % mo);
        p[cnt] = p[cnt] + d[1];
        while (cnt > 1 && p[cnt].w >= 0)
          p[cnt - 1] = p[cnt - 1] + p[cnt], cnt--;
      }
      add(sum, p[1].v);
      for (i = 2; i <= cnt; i++) add(sum, (long long)2 * p[i].v % mo);
      an[q[s++].id] = sum;
    }
  }
  for (i = 1; i <= m; i++) printf("%d\n", an[i]);
  return 0;
}
