#include <bits/stdc++.h>
using namespace std;
int n, q, i, l, r, MOD = 1e9 + 7, t[100005 * 4], sum[100005];
int solve(int k, int len) { return (sum[len] - sum[len - k] + MOD) % MOD; }
void build(int l, int r, int node) {
  if (l == r) {
    t[node] = getchar() - 48;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, node << 1), build(mid + 1, r, node << 1 | 1);
  t[node] = t[node << 1] + t[node << 1 | 1];
}
int ask(int l, int r, int a, int b, int node) {
  if (l == a && r == b) return t[node];
  int mid = (l + r) >> 1;
  if (b <= mid) return ask(l, mid, a, b, node << 1);
  if (a > mid) return ask(mid + 1, r, a, b, node << 1 | 1);
  return ask(l, mid, a, mid, node << 1) +
         ask(mid + 1, r, mid + 1, b, node << 1 | 1);
}
int main() {
  scanf("%d%d\n", &n, &q);
  build(1, n, 1);
  for (i = 1, sum[0] = 1; i <= n; i++) sum[i] = sum[i - 1] * 2 % MOD;
  for (i = 1; i <= q; i++) {
    scanf("%d%d", &l, &r);
    printf("%d\n", solve(ask(1, n, l, r, 1), r - l + 1));
  }
  return 0;
}
