#include <bits/stdc++.h>
using namespace std;
long long power(long long n, long long x) {
  if (x == 0) return 1;
  if (x & 1) {
    return (n * (power((n * n) % 1000000007, x / 2))) % 1000000007;
  } else {
    return (power((n * n) % 1000000007, x / 2)) % 1000000007;
  }
}
void solve() {
  long long n;
  long long q;
  cin >> n;
  cin >> q;
  string s;
  cin >> s;
  long long pre[n][2];
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      if (s[i] == '1') {
        pre[i][0] = 0;
        pre[i][1] = 1;
      } else {
        pre[i][0] = 1;
        pre[i][1] = 0;
      }
    } else {
      if (s[i] == '1') {
        pre[i][0] = pre[i - 1][0];
        pre[i][1] = pre[i - 1][1] + 1;
      } else {
        pre[i][0] = pre[i - 1][0] + 1;
        pre[i][1] = pre[i - 1][1];
      }
    }
  }
  while (q--) {
    long long l, r;
    cin >> l >> r;
    l--;
    r--;
    long long o, z;
    if (l - 1 >= 0) {
      o = pre[r][1] - pre[l - 1][1];
      z = pre[r][0] - pre[l - 1][0];
    } else {
      o = pre[r][1];
      z = pre[r][0];
    }
    long long oneSum = power(2, o) - 1;
    long long zeroSum = (oneSum * (power(2, z) - 1)) % 1000000007;
    cout << (oneSum + zeroSum) % 1000000007 << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
