#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 322;
const long long maxn = 1e5 + 228;
const long long MOD = 1e9 + 7;
long long n, q, pr[maxn];
long long bin_pow(long long a, long long n) {
  if (n == 0) return 1;
  if (n & 1) {
    return (bin_pow(a, n - 1) * a) % MOD;
  } else {
    long long b = bin_pow(a, n / 2);
    return (b * b) % MOD;
  }
}
void solve() {
  string s;
  cin >> n >> q;
  cin >> s;
  for (int i = 1; i <= n; ++i) {
    pr[i] = pr[i - 1] + (s[i - 1] == '1');
  }
  while (q--) {
    long long l, r, tmp = 1, kol1 = 0, kol0 = 0, ans = 0, mul;
    cin >> l >> r;
    kol1 = pr[r] - pr[l - 1];
    kol0 = r - l + 1 - kol1;
    if (kol1) {
      tmp = bin_pow(2, kol1);
      ans = (tmp - 1 + MOD) % MOD;
    }
    if (kol0) {
      tmp = (tmp - 1 + MOD) % MOD;
      long long tmp1 = bin_pow(2, kol0);
      ans = (ans + ((tmp * (tmp1 - 1 + MOD)) % MOD)) % MOD;
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  solve();
  return 0;
}
