#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
vector<long long> p;
int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  p.resize(1e5 + 1);
  p[0] = 1;
  for (int i = 1; i <= 1e5; i++) {
    p[i] = (p[i - 1] * 2) % MOD;
  }
  vector<long long> kum(n + 1);
  kum[0] = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      kum[i + 1] = kum[i] + 1;
    } else {
      kum[i + 1] = kum[i];
    }
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    long long kol_1 = kum[r] - kum[l - 1];
    long long kol_0 = r - l + 1 - kol_1;
    long long ans_1 = p[kol_1] - 1;
    long long ans_0 = ans_1 * (p[kol_0] - 1);
    cout << (ans_1 + ans_0) % MOD << '\n';
  }
  return 0;
}
