#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;
template <typename T>
void cout_join(vector<T> &v, string d = " ") {
  for (int i = (0); i < (v.size()); ++i) {
    if (i > 0) cout << d;
    cout << v[i];
  }
  cout << endl;
}
template <typename T>
long long int power(T n, T p, T m) {
  if (p == 0) return 1LL;
  if (p == 1) return n;
  long long int k = power(n, p / 2, m);
  return ((k * k) % m * (p % 2 ? n : 1)) % m;
}
const long long int mod = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<long long int> sum(n + 1, 0);
  for (int i = (1); i <= (n); ++i) {
    sum[i] = sum[i - 1] + (s[i - 1] - '0');
  }
  for (int i = (0); i < (q); ++i) {
    long long int l, r;
    cin >> l >> r;
    long long int cnt1 = sum[r] - sum[l - 1], cnt0 = r - (l - 1) - cnt1;
    long long int enj = (power(2LL, cnt1, mod) - 1 + mod) % mod;
    enj += (enj * ((power(2LL, cnt0, mod) - 1 + mod) % mod)) % mod;
    enj %= mod;
    cout << enj << endl;
  }
  return 0;
}
