#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fod(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int maxn=100007;
int i,j,k,l,n,m,ans,r,mid;
char s[maxn];
int rank[maxn],sa[maxn],h[maxn],height[maxn],p[maxn],da,zhi[maxn];
int a,b,c,d,fu[maxn],root[maxn],g[maxn][21],zuo,you,num;
struct node{
int l,r,sum;
}t[maxn*20];
void getsa(){
int i,j=0,k,o;
fo(i,1,n)rank[i]=s[i];
fo(k,1,n){
if(k==1)j=0;else if(k==2)j=1;else j*=2;
if(j>n)break;
memset(p,0,sizeof(p));
fo(i,1,n)p[rank[i+j]]++;
fo(i,1,da)p[i]+=p[i-1];
fod(i,n,1)zhi[p[rank[i+j]]--]=i;
memset(p,0,sizeof(p));
fo(i,1,n)p[rank[i]]++;
fo(i,1,da)p[i]+=p[i-1];
fod(i,n,1)sa[p[rank[zhi[i]]]--]=zhi[i];
fu[sa[1]]=1;o=1;
fo(i,2,n)fu[sa[i]]=(rank[sa[i]]!=rank[sa[i-1]]||rank[sa[i]+j]!=rank[sa[i-1]+j])?(++o):o;
swap(fu,rank);
}
}
void insert(int &x,int y,int l,int r,int z){
x=++num;
t[x]=t[y];t[x].sum+=1;
if(l==r)return;
int mid=(l+r)/2;
if(z<=mid)insert(t[x].l,t[y].l,l,mid,z);
else insert(t[x].r,t[y].r,mid+1,r,z);
}
int find(int x,int y,int l,int r,int u,int v){
if(l==u&&r==v){
return t[y].sum-t[x].sum;
}
int mid=(l+r)/2;
if(v<=mid)return find(t[x].l,t[y].l,l,mid,u,v);
else if(u>mid)return find(t[x].r,t[y].r,mid+1,r,u,v);
else return find(t[x].l,t[y].l,l,mid,u,mid)+find(t[x].r,t[y].r,mid+1,r,mid+1,v);
}
void geth(){
fo(i,1,n){
if(rank[i]==1)continue;
while(i+k<=n&&s[i+k]==s[sa[rank[i]-1]+k])k++;
height[rank[i]]=k;
if(k)k--;
}
}
void getrmq(){
fo(i,1,n)g[i][0]=height[i];
fo(j,1,20){
fo(i,1,n){
if(i+(1<<(j-1))>n)break;
g[i][j]=min(g[i][j-1],g[i+(1<<(j-1))][j-1]);
}
}
}
int main(){
// freopen("fan.in","r",stdin);
scanf("%d%d",&n,&m);
scanf("%s",s+1);da=n;
getsa();geth();getrmq();
fo(i,1,n)insert(root[i],root[i-1],1,n,rank[i]);
fo(j,1,m){
scanf("%d%d%d%d",&a,&b,&c,&d);
l=1,r=min(b-a+1,d-c+1);ans=0;
while(l<=r){
mid=(l+r)/2;
zuo=you=rank[c];
fod(i,20,0)if(zuo>=(1<<i)&&g[zuo-(1<<i)+1][i]>=mid)zuo-=(1<<i);
fod(i,20,0)if(you+(1<<i)<=n&&g[you+1][i]>=mid)you+=(1<<i);
if(find(root[a-1],root[b-mid+1],1,n,zuo,you)>0)ans=mid,l=mid+1;
else r=mid-1;
}
printf("%d\n",ans);
}
}