#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const long long MOD = 1e9 + 7;
int n, q, arr[MAX];
long long pp[MAX];
long long pro(int cnt, int len) {
  long long ans = pp[cnt] - 1;
  ans += (pp[len - cnt] - 1) * ans;
  return (ans % MOD + MOD) % MOD;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  pp[0] = 1;
  for (int i = 1; i < MAX; i++) pp[i] = pp[i - 1] * 2 % MOD;
  cin >> n;
  cin >> q;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    if (c == '1') arr[i] = 1;
    arr[i] += arr[i - 1];
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    int cnt = arr[r] - arr[l - 1];
    int len = r - l + 1;
    cout << pro(cnt, len) << '\n';
  }
}
