#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  if (b < 0) return 0;
  long long ret = 1;
  a %= mod;
  while (b) {
    if (b & 1) ret = (ret * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ret;
}
char num[10000001];
int a[1000001][3];
int main() {
  int n, q;
  cin >> n >> q >> num;
  for (int i = 0; i < n; i++) {
    if (num[i] == '0') {
      a[i + 1][0] = (a[i][0] + 1) % mod;
      a[i + 1][1] = a[i][1];
    } else {
      a[i + 1][1] = (a[i][1] + 1) % mod;
      a[i + 1][0] = a[i][0];
    }
  }
  while (q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    long long T1, T2;
    int num1 = a[v][1] - a[u - 1][1];
    T1 = qpow(2, num1) - 1;
    int num0 = a[v][0] - a[u - 1][0];
    T2 = qpow(2, num0) - 1;
    T2 = (T2 * T1) % mod;
    cout << (T1 + T2) % mod << endl;
  }
}
