#include <bits/stdc++.h>
using namespace std;
long long int M1 = 1000000007;
const int M2 = 998244353;
const int N = 100005;
int ones[N];
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
long long int GPmodM(long long int a, long long int r, long long int n) {
  return (a * (modpow(r, n, M1) - 1) * modpow(r - 1, M1 - 2, M1)) % M1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m, q, a, b, temp;
  cin >> n >> q;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      ones[i + 1] = ones[i] + 1;
    } else {
      ones[i + 1] = ones[i];
    }
  }
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    int length = b - a + 1;
    int one = ones[b] - ones[a - 1];
    int zero = length - one;
    if (zero == length) {
      cout << 0 << "\n";
    } else {
      long long int ans = modpow(2 * 1LL, 1LL * one, M1) - 1;
      ans += GPmodM(ans, 1LL * 2, zero);
      cout << ans % M1 << "\n";
    }
  }
}
