#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long solve(long long good, long long len, vector<long long> &pow) {
  long long rest = len - good;
  long long ans = pow[good] - 1;
  long long help = (ans * (pow[rest] - 1)) % mod;
  ans += help;
  ans %= mod;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<long long> pow(100005);
  pow[0] = 1;
  for (int i = 1; i < 1e5 + 5; i++) {
    pow[i] = (pow[i - 1] * 2) % mod;
  }
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int x;
  vector<int> pref(n + 1);
  pref[0] = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      x = 0;
    else
      x = 1;
    pref[i + 1] = pref[i] + x;
  }
  int L, R;
  for (int i = 0; i < q; i++) {
    cin >> L >> R;
    int len = (R - L + 1);
    int good = pref[R] - pref[L - 1];
    cout << solve(good, len, pow) << endl;
  }
}
