#include <bits/stdc++.h>
using namespace std;
const int N = 1<<20;
struct pair_hash {
long long operator()(const pair <int, int> &a) const {
return a.first*1ll*1000000000+a.second;
}
};
int n,m;
char a[N];
unordered_map < pair <int, int> , bool, pair_hash> used;
unordered_map < pair <int, int> , int, pair_hash> state;
bool check(int x, int y, int z, int w) {
int i=x,j=z;
while(i<=y) {
if(a[i]!=a[j]) return false;
++i;
++j;
}
return true;
}
int recurse(int l, int r) {
if(r>n) return 0;
if(used[make_pair(l,r)]) return state[make_pair(l,r)];
int ans=1,length=r-l+1;
if(check(l,r,l+length,r+length)) ans+=recurse(l+length,r+length);
used[make_pair(l,r)]=true;
state[make_pair(l,r)]=ans;
return ans;
}
int main() {
int i,cnt,l,r;
scanf("%d %d", &n, &m);
scanf("%s", a+1);
while(m--) {
scanf("%d %d", &l, &r);
/*cnt=1;
for(i=r+1;i+(r-l+1)-1<=n;i+=(r-l+1)) {
if(check(l,r,i,i+(r-l+1)-1)) ++cnt;
else break;
}
printf("%d\n", cnt);*/
printf("%d\n", recurse(l,r));
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAxPDwyMDsKCnN0cnVjdCBwYWlyX2hhc2ggewogICAgbG9uZyBsb25nIG9wZXJhdG9yKCkoY29uc3QgcGFpciA8aW50LCBpbnQ+ICZhKSBjb25zdCB7CiAgICAgICAgcmV0dXJuIGEuZmlyc3QqMWxsKjEwMDAwMDAwMDArYS5zZWNvbmQ7CiAgICB9Cn07CgppbnQgbixtOwpjaGFyIGFbTl07CnVub3JkZXJlZF9tYXAgPCBwYWlyIDxpbnQsIGludD4gLCBib29sLCBwYWlyX2hhc2g+IHVzZWQ7CnVub3JkZXJlZF9tYXAgPCBwYWlyIDxpbnQsIGludD4gLCBpbnQsIHBhaXJfaGFzaD4gc3RhdGU7Cgpib29sIGNoZWNrKGludCB4LCBpbnQgeSwgaW50IHosIGludCB3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