#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  if ("" == "input") {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  } else if ("" != "") {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  int t = 1;
  if (0) {
    cin >> t;
  }
  while (t--) solve();
  return 0;
}
const int mod = (int)1e9 + 7;
void solve() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<long long> p(n + 1);
  for (int i = 0; i < n; ++i) {
    p[i + 1] = p[i] + (s[i] - '0');
  }
  vector<long long> pw(n + 1);
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pw[i] = 2ll * pw[i - 1] % mod;
  }
  vector<long long> G(n + 1);
  G[1] = 1;
  for (int i = 2; i <= n; ++i) {
    G[i] = (pw[i] - 1 + mod) % mod;
  }
  for (int i = 0; i <= n; ++i) {
    42;
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    int N = r - l + 1;
    int cnt = p[r + 1] - p[l];
    42;
    cout << (G[N] - 1ll * G[N - cnt] % mod + mod) % mod << "\n";
  }
}
