#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1, mod = 1e9 + 7;
int n, q;
long long arr[N];
long long pref[N];
long long binpow(long long a, long long s) {
  long long ans = 1;
  while (s) {
    if (s & 1) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    s >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c;
    if (c == '1') arr[i] = 1;
    pref[i] = pref[i - 1] + arr[i];
  }
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    long long len = r - l + 1, cnt = pref[r] - pref[l - 1];
    cout << ((binpow(2, cnt) - 1) * binpow(2, len - cnt)) % mod << endl;
  }
}
