#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
class segTree {
 private:
  vector<int> seg;

 public:
  segTree(int n = 0) { seg.assign(4 * n + 7, 0); }
  void build(int k, int l, int r, int x, int val) {
    if (x < l || r < x) return;
    if (l == r) {
      seg[k] = val;
      return;
    }
    int mid = (l + r) / 2;
    build(k * 2, l, mid, x, val);
    build(k * 2 + 1, mid + 1, r, x, val);
    seg[k] = seg[k * 2] + seg[k * 2 + 1];
  }
  int get(int k, int l, int r, int u, int v) {
    if (v < l || u > r) return 0;
    if (u <= l && r <= v) return seg[k];
    int mid = (l + r) / 2;
    return get(k * 2, l, mid, u, v) + get(k * 2 + 1, mid + 1, r, u, v);
  }
};
int p[200000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  char s;
  segTree seg(n);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    seg.build(1, 1, n, i, s - '0');
  }
  p[0] = 1;
  for (int i = 1; i <= n; i++) p[i] = (1ll * p[i - 1] * 2) % MOD;
  for (int i = 0; i < q; i++) {
    int u, v;
    cin >> u >> v;
    int g1 = seg.get(1, 1, n, u, v);
    int g0 = v - u + 1 - g1;
    long long ans = (p[g1] - 1 + MOD) % MOD;
    ans = 1ll * p[g0] * ans % MOD;
    cout << ans << "\n";
  }
  return 0;
}
