#include <bits/stdc++.h>
using namespace std;
long long n, q, sum[100004], mod = 1e9 + 7;
string s;
long long get_sum(long long i, long long j) {
  if (i == 0) return sum[j];
  return sum[j] - sum[i - 1];
}
long long expo(long long v, long long e) {
  if (v == 0) return 0;
  if (e == 0) return 1;
  if (e == 1) return v;
  long long x = expo(v, e / 2);
  x = (x * x) % mod;
  if (e % 2 == 1) {
    x = (x * v) % mod;
  }
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  cin >> s;
  sum[0] = (long long)(s[0] == '1');
  for (int i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + (long long)(s[i] == '1');
  }
  for (int i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    long long ones = get_sum(a, b);
    long long finaln = (expo(2, ones) - 1 + mod) % mod;
    long long ans = ((expo(2, b - a + 1 - ones) - 1) * finaln + finaln) % mod;
    while (ans < 0) {
      ans = (ans + mod) % mod;
    }
    cout << ans << endl;
  }
  return 0;
}
