#include <bits/stdc++.h>
using namespace std;
inline int M(int x) { return (x >= 1000000007) ? (x - 1000000007) : x; }
inline int M1(int x) { return (x < 0) ? (x + 1000000007) : x; }
int n, Q, P[100012], a[100012], tp = 0, s1[100012], s2[100012], ql[100012],
                                ans[100012];
long long s[100012];
vector<int> q[100012];
struct sec {
  int l, r;
  long long v;
  inline bool operator<(const sec &b) const { return (r < b.r); }
} st[100012];
inline long long mul(int le, long long v) {
  return (v == 0) ? 0
                  : ((le >= 60) ? 0x3f3f3f3f3f3f3f3fll
                                : ((v <= (0x3f3f3f3f3f3f3f3fll >> le))
                                       ? (v << le)
                                       : 0x3f3f3f3f3f3f3f3fll));
}
inline sec Me(sec x, sec y) {
  return (sec){x.l, y.r,
               min(1ll * 0x3f3f3f3f3f3f3f3fll, x.v + mul(x.r - x.l + 1, y.v))};
}
inline int cal(sec x) {
  return M1(s1[x.l] - 1ll * s1[x.r + 1] * P[x.r - x.l + 1] % 1000000007);
}
int main() {
  P[0] = 1;
  for (int i = 1; i < 100012; i++) P[i] = M(P[i - 1] << 1);
  scanf("%d%d", &n, &Q);
  int i, l, r, x;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
  for (i = n; i >= 1; i--) s1[i] = M(M(s1[i + 1] << 1) + M1(a[i]));
  for (i = 1; i <= Q; i++) scanf("%d%d", &l, &r), ql[i] = l, q[r].push_back(i);
  for (i = 1; i <= n; i++) {
    st[++tp] = (sec){i, i, a[i]};
    while ((tp > 1) && (st[tp].v >= 0))
      st[tp - 1] = Me(st[tp - 1], st[tp]), --tp;
    s2[tp] = M(s2[tp - 1] + M(cal(st[tp]) << 1));
    for (auto o : q[i])
      l = ql[o], x = lower_bound(st + 1, st + tp + 1, (sec){0, l, 0}) - st,
      ans[o] = M(M1(s2[tp] - s2[x]) + cal((sec){l, st[x].r, 0}));
  }
  for (i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}
