#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int bp(int x, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res = (long long)res * x % mod;
    x = (long long)x * x % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> px(n + 1);
  px[0] = 0;
  for (int i = 1; i <= n; ++i) {
    px[i] = px[i - 1];
    if (s[i - 1] == '1') ++px[i];
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    int k = px[r] - px[l - 1];
    int a = bp(2, k) - 1;
    if (a == -1) a = mod - 1;
    k = r - l + 1 - k;
    int b = bp(2, k);
    int s = (long long)a * b % mod;
    cout << s << endl;
  }
  return 0;
}
