#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int val[maxn];
long long poww[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  string t;
  cin >> t;
  poww[0] = 1;
  for (int i = 1; i < maxn; ++i) {
    poww[i] = poww[i - 1] * 2 % 1000000007;
  }
  for (int i = 0; i < t.size(); ++i) {
    a[i + 1] = t[i] - '0';
  }
  for (int i = 1; i <= n; ++i) {
    val[i] = val[i - 1] + a[i];
  }
  int l, r;
  for (int i = 1; i <= q; ++i) {
    cin >> l >> r;
    int cnt1 = val[r] - val[l - 1];
    int cnt0 = r - l + 1 - cnt1;
    long long ans = 0;
    ans += (poww[cnt1] - 1 + 1000000007) % 1000000007;
    if (cnt0) {
      long long tans;
      tans = ((poww[cnt0 - 1] * ans * 2) % 1000000007 - ans + 1000000007) %
             1000000007;
      ans += tans;
      ans %= 1000000007;
    }
    cout << ans << endl;
  }
  return 0;
}
