#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long int INF = LLONG_MAX;
const long long int mod = 1e9 + 7;
long long int powfast(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<long long int> a(n + 1, 0);
  for (long long int i = 0; i <= n - 1; i++) {
    if (s[i] == '1')
      a[i + 1] = a[i] + 1;
    else
      a[i + 1] = a[i];
  }
  for (long long int i = 0; i <= q - 1; i++) {
    long long int l, r;
    cin >> l >> r;
    long long int nos1 = a[r] - a[l - 1];
    long long int nos0 = r - l - nos1 + 1;
    long long int ans = (powfast(2, nos0) * (powfast(2, nos1) - 1)) % mod;
    cout << ans << endl;
  }
  return 0;
}
