#include <bits/stdc++.h>
using namespace std;
long long me(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) return me((a * a) % 1000000007, b / 2);
  if (b % 2 == 1) return (a * me((a * a) % 1000000007, b / 2)) % 1000000007;
}
void solve() {
  long long n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  long long a[n + 1];
  a[0] = 0;
  for (long long int i = 0; i < n; i++) {
    a[i + 1] = a[i];
    if (s[i] == '1') a[i + 1]++;
  }
  while (q--) {
    long long a1, b1;
    cin >> a1 >> b1;
    long long x = a[b1] - a[a1 - 1];
    if (x == 0) {
      cout << 0 << '\n';
      continue;
    }
    long long an;
    long long y = b1 - a1 + 1 - x;
    an = (me(2, x) - 1 + 1000000007) % 1000000007;
    an = (an + (an * (me(2, y) - 1 + 1000000007) % 1000000007) % 1000000007) %
         1000000007;
    cout << an << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
