#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
const long double eps = 1e-10L;
long long one[300005], zero[300005];
vector<long long> v;
void pw() {
  long long val = 1;
  long long temp = 1;
  v.push_back(val);
  for (long long i = 1; i <= 300005; i++) {
    temp *= 2;
    temp %= (long long)(1000 * 1000 * 1000 + 7);
    val += temp;
    val %= (long long)(1000 * 1000 * 1000 + 7);
    v.push_back(val);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, q;
  cin >> n >> q;
  pw();
  string s;
  cin >> s;
  for (long long i = 1; i <= n; i++) {
    if (s[i - 1] == '1')
      one[i]++;
    else
      zero[i]++;
    one[i] += one[i - 1];
    zero[i] += zero[i - 1];
  }
  while (q--) {
    long long a, b;
    cin >> a >> b;
    long long o = one[b] - one[a - 1];
    long long z = zero[b] - zero[a - 1];
    long long ans = v[o + z - 1];
    if (z > 0) ans -= v[z - 1];
    ans += (long long)(1000 * 1000 * 1000 + 7);
    ans %= (long long)(1000 * 1000 * 1000 + 7);
    cout << ans << "\n";
  }
}
