#include <bits/stdc++.h>
using namespace std;
long long int modular_exp(long long int A, long long int B, long long int C) {
  if (B == 0) return 1;
  if (B == 1) return A;
  long long int res = A;
  if (res > C) res = res % C;
  int counter = 2;
  while (counter < B) {
    res = res * res;
    if (res > C) res = res % C;
    counter *= 2;
    if (counter >= B) break;
  }
  counter /= 2;
  return ((res % C) * modular_exp(A, B - counter, C)) % C;
}
long long int Mod(long long int A, long long int B, long long int C) {
  if (A == 0) return 0;
  if (C == 1) return 0;
  long long int res = modular_exp(A, B, C);
  if (res < 0) return C + res;
  if (B == 0) return 1;
  return res;
}
long long int ans__(long long int num_one, long long int num_zero) {
  long long int ans =
      ((Mod(2, num_one, 1000000007) - 1) + 1000000007) % 1000000007;
  long long int ans_2 =
      ((Mod(2, num_zero, 1000000007) - 1) + 1000000007) % 1000000007;
  ans_2 = (ans % 1000000007 * ans_2 % 1000000007) % 1000000007;
  return (ans % 1000000007 + ans_2 % 1000000007) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  for (int u = 0; u < t; u++) {
    long long int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<long long int> ones, zeros;
    long long int num_ones = 0;
    long long int num_zeros = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0') num_zeros++;
      if (s[i] == '1') num_ones++;
      ones.push_back(num_ones);
      zeros.push_back(num_zeros);
    }
    for (int i = 0; i < q; i++) {
      long long int l, r;
      cin >> l >> r;
      l--;
      r--;
      long long int one, zero;
      if (l > 0) {
        one = ones[r] - ones[l - 1];
        zero = zeros[r] - zeros[l - 1];
      } else if (l == 0) {
        one = ones[r];
        zero = zeros[r];
      }
      cout << ans__(one, zero) << "\n";
    }
  }
  return 0;
}
