#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
long long a[100005] = {0};
string str;
long long quickpow(long long a, long long n) {
  long long ans = 1;
  long long tmp = a % mod;
  while (n) {
    if (n & 1) {
      ans = ((ans) % mod * (tmp) % mod) % mod;
    }
    tmp = ((tmp % mod) * (tmp) % mod) % mod;
    n >>= 1;
  }
  return ans % mod;
}
int main() {
  long long n, q;
  cin >> n >> q;
  cin >> str;
  long long len = str.size();
  for (long long i = 0; i < len; i++) {
    if (str[i] == '1') {
      a[i + 1] = a[i] + 1;
    } else {
      a[i + 1] = a[i];
    }
  }
  long long l, r;
  while (q--) {
    cin >> l >> r;
    long long b = (r - l + 1) % mod;
    long long c = b - a[r] + a[l - 1];
    cout << (quickpow(2, b) % mod - quickpow(2, c) % mod + mod) % mod << endl;
  }
}
