#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int n, q, x, y, z, h;
string s;
long long a[100005], b[100005];
void init() {
  b[0] = 1;
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1] * 2 % mod;
  }
}
int main() {
  cin >> n >> q;
  cin >> s;
  init();
  for (int i = 0; i < n; i++) a[i] = a[i - 1] + s[i] - 48;
  while (q--) {
    cin >> x >> y;
    if (x == 1)
      z = a[y - 1];
    else
      z = a[y - 1] - a[x - 2];
    h = y - x + 1;
    long long ans = (b[h] - b[h - z] + mod) % mod;
    cout << ans << endl;
  }
}
