#include <bits/stdc++.h>
using namespace std;
string s;
int ar[100005];
int ans[100005];
int anss[100005];
int main() {
  int n, q, i, l, r, j, a, b, x;
  ans[0] = 1;
  for (i = 1; i < 100005; i++) {
    ans[i] = (ans[i - 1] * 2) % 1000000007;
  }
  anss[0] = 1;
  for (i = 1; i < 100005; i++) {
    anss[i] = (anss[i - 1] + ans[i]) % 1000000007;
  }
  scanf("%d %d", &n, &q);
  cin >> s;
  ar[1] = s[0] - '0';
  for (i = 2; i <= s.size(); i++) {
    ar[i] = ar[i - 1] + s[i - 1] - '0';
  }
  for (i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    a = ar[r] - ar[l - 1];
    b = r - l + 1;
    b -= a;
    x = (anss[a + b - 1] - anss[b - 1] + 1000000007) % 1000000007;
    printf("%d\n", x);
  }
  return 0;
}
