#include <bits/stdc++.h>
using namespace std;
long long power(long long x, unsigned long long y) {
  int res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
int main() {
  int n, q;
  vector<int> one(100005, 0), zero(100005, 0);
  string s;
  cin >> n >> q;
  cin >> s;
  for (int i = 1; i <= n; i++) {
    zero[i] = zero[i - 1];
    one[i] = one[i - 1];
    if (s[i - 1] == '0')
      zero[i]++;
    else
      one[i]++;
  }
  int l, r;
  while (q--) {
    cin >> l >> r;
    int z = zero[r] - zero[l - 1];
    int o = one[r] - one[l - 1];
    long long ans = power(2, o) - 1;
    long long aa = power(2, z) - 1;
    long long b = (aa % 1000000007 * ans % 1000000007) % 1000000007;
    cout << (ans % 1000000007 + b % 1000000007) % 1000000007 << "\n";
  }
  return 0;
}
