#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 1e5 + 134, M = 1e9 + 7;
int64_t pr[MAXN], q[MAXN];
int64_t F(int64_t i) {
  if (i == 0) return 1;
  int64_t x = F(i / 2);
  if (i % 2 == 0)
    return (x * x) % M;
  else
    return (2 * x * x) % M;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int64_t n, k, x;
  cin >> n >> k;
  pr[0] = 0;
  for (int64_t i = 0; i < n; i++) {
    char c;
    cin >> c;
    q[i] = c - '0';
    pr[i + 1] = pr[i] + q[i];
  }
  for (int64_t i = 0; i < k; i++) {
    int64_t l, r;
    cin >> l >> r;
    l--;
    r--;
    int64_t a = pr[r + 1] - pr[l];
    int64_t b = r - l + 1 - a;
    int64_t ans;
    ans = ((F(a) + M - 1) % M * F(b)) % M;
    cout << ans << "\n";
  }
  return 0;
}
