#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f;
long long a[N], sum[N];
long long q_pow(long long a, long long k) {
  long long s = 1;
  while (k) {
    if (k & 1) s = s * a % mod;
    a = a * a % mod;
    k >>= 1;
  }
  return s;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int _;
  _ = 1;
  while (_--) {
    long long n, m, inv2 = q_pow(2, mod - 2);
    string s;
    cin >> n >> m >> s;
    s = " " + s;
    for (int i = 1; (i) <= (n); i++) sum[i] = sum[i - 1] + s[i] - '0';
    while (m--) {
      long long l, r;
      cin >> l >> r;
      long long sum1 = sum[r] - sum[l - 1];
      if (sum1 == 0) {
        cout << 0 << '\n';
        continue;
      }
      long long sum0 = r - l + 1 - sum1;
      long long ans = q_pow(2, sum1) - 1;
      long long now = ans;
      ans = (ans + now * (q_pow(2, sum0) - 1) % mod) % mod;
      cout << ans << '\n';
    }
  }
  return 0;
}
