#include <bits/stdc++.h>
using namespace std;
long long calc_power(long long x) {
  if (x == 0) {
    return 1L;
  }
  long long t = calc_power(x / 2L);
  if (x % 2) {
    return ((t * t) * 2L) % 1000000007L;
  }
  return ((t * t)) % 1000000007L;
}
int main() {
  long long n, q;
  cin >> n >> q;
  vector<long long> arr(n + 1, 0);
  string s;
  cin >> s;
  arr[0] = 0;
  for (long long i = 1; i <= n; i++) {
    arr[i] = arr[i - 1] + (s[i - 1] - '0');
  }
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    long long ones = arr[r] - arr[l - 1];
    long long zeros = r - l + 1 - ones;
    long long x = 1;
    x = calc_power(ones);
    x -= 1;
    x *= calc_power(zeros);
    x %= 1000000007L;
    cout << x << endl;
  }
}
