#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  cerr << "Completed in " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds\n";
}
const long long INF = 1e9;
const long long N = 1e5 + 5;
const long long MOD = 1e9 + 7;
long long n, q, l, r, f[N];
string s;
long long modpow(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b & 1) (res *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return res;
}
void solve() {
  cin >> n >> q;
  cin >> s;
  for (long long i = 1; i <= n; i++) {
    f[i] = f[i - 1] + (s[i - 1] == '1');
  }
  for (long long i = 1; i <= q; i++) {
    cin >> l >> r;
    long long x = r - l + 1;
    long long y = x - (f[r] - f[l - 1]);
    long long ans = modpow(2, x, MOD) - 1;
    ans -= modpow(2, y, MOD) - 1;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << "\n";
  }
}
