#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"

const int K=30;

struct Vertex {
    int next[K];
    bool leaf=false;
    int p=-1; char ch;
    int link=-1, slink=-1; int go[K];
    vi idx;
    Vertex(int p=-1, char ch='#'): p(p), ch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

struct Trie {
    vector<Vertex> trie; int n=0;
    void add(const string& s, int id) {
        int v=0;
        for(char ch: s) {
            int c=ch-'a';
            if(trie[v].next[c]==-1) {
                trie[v].next[c]=trie.size();
                trie.emplace_back(v, ch);
            }
            v=trie[v].next[c];
        }
        trie[v].leaf=true;
        trie[v].idx.pb(id);
    }
    Trie() {trie=vector<Vertex>(1);}
    Trie(vector<string>& s) {trie=vector<Vertex>(1); for(string& it: s) add(it, n++);}
    int go(int v, char ch);
    int get_link(int v) {
        if(trie[v].link==-1) {
            if(v==0||trie[v].p==0) trie[v].link=0;
            else trie[v].link=go(get_link(trie[v].p), trie[v].ch);
        }
        return trie[v].link;
    }
    int get_suff_link(int v) {
        if(trie[v].slink==-1) {
            if(get_link(v)==0||trie[get_link(v)].leaf) trie[v].slink=get_link(v);
            else trie[v].slink=get_suff_link(get_link(v));
        }
        return trie[v].slink;
    }
};

int Trie::go(int v, char ch) {
    int c=ch-'a';
    if(trie[v].go[c]==-1) {
        if(trie[v].next[c]!=-1) trie[v].go[c]=trie[v].next[c];
        else trie[v].go[c]=v==0?0:go(get_link(v), ch);
    }
    return trie[v].go[c];
}

struct Aho_Corasick {
    string s; Trie t;
    Aho_Corasick(string s, Trie t): s(s), t(t) {}
    Aho_Corasick(string s, vector<string>& vt): s(s), t(Trie(vt)) {}
    const vector<pii> get() {
        vector<pii> res;
        int v=0;
        for(int i=0;i<s.length();i++)
		{
            v=t.go(v, s[i]);
            int _v=v;
            while(_v!=0) {
                if(t.trie[_v].leaf) for(int id: t.trie[_v].idx) res.pb({i, id});
                _v=t.get_suff_link(_v);
            }
        }
        return res;
    }
};
int arr[100005];
int len[100005];

int main()
{
    //freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
    int n;
        string s;
        cin>>s>>n;
		vector<string> t(n);
        for(int i=0;i<n;i++)
        {
        	cin>>arr[i]>>t[i];
        	len[i] = t[i].length();
        	assert(len[i] >= 0);
		}
        vector<pii> res=Aho_Corasick(s,t).get();
       	vector<vi> ans(n);
        for(auto it: res)
			ans[it.se].pb(it.fi-int(t[it.se].length())+1);
        for(int i=0;i<n;i++)
		{
			int dap_ans = 1e9+7;
			for (int j = 0; j < int(ans[i].size()) - arr[i] + 1; j++)
			{
				dap_ans = min(dap_ans, ans[i][j + arr[i]-1] - ans[i][j] + len[i]);
			}
			if (dap_ans == 1e9+7)
				dap_ans = -1;
			cout << dap_ans << endl;
		}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"

const int K=96;

struct Vertex {
    int next[K];
    bool leaf=false;
    int p=-1; char ch;
    int link=-1, slink=-1; int go[K];
    vi idx;
    Vertex(int p=-1, char ch='#'): p(p), ch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

struct Trie {
    vector<Vertex> trie; int n=0;
    void add(const string& s, int id) {
        int v=0;
        for(char ch: s) {
            int c=ch-32;
            if(trie[v].next[c]==-1) {
                trie[v].next[c]=trie.size();
                trie.emplace_back(v, ch);
            }
            v=trie[v].next[c];
        }
        trie[v].leaf=true;
        trie[v].idx.pb(id);
    }
    Trie() {trie=vector<Vertex>(1);}
    Trie(vector<string>& s) {trie=vector<Vertex>(1); for(string& it: s) add(it, n++);}
    int go(int v, char ch);
    int get_link(int v) {
        if(trie[v].link==-1) {
            if(v==0||trie[v].p==0) trie[v].link=0;
            else trie[v].link=go(get_link(trie[v].p), trie[v].ch);
        }
        return trie[v].link;
    }
    int get_suff_link(int v) {
        if(trie[v].slink==-1) {
            if(get_link(v)==0||trie[get_link(v)].leaf) trie[v].slink=get_link(v);
            else trie[v].slink=get_suff_link(get_link(v));
        }
        return trie[v].slink;
    }
};

int Trie::go(int v, char ch) {
    int c=ch-32;
    if(trie[v].go[c]==-1) {
        if(trie[v].next[c]!=-1) trie[v].go[c]=trie[v].next[c];
        else trie[v].go[c]=v==0?0:go(get_link(v), ch);
    }
    return trie[v].go[c];
}

struct Aho_Corasick {
    string s; Trie t;
    Aho_Corasick(string s, Trie t): s(s), t(t) {}
    Aho_Corasick(string s, vector<string>& vt): s(s), t(Trie(vt)) {}
    const vector<pii> get() {
        vector<pii> res;
        int v=0;
        for(int i=0;i<s.length();i++)
		{
            v=t.go(v, s[i]);
            int _v=v;
            while(_v!=0) {
                if(t.trie[_v].leaf) for(int id: t.trie[_v].idx) res.pb({i, id});
                _v=t.get_suff_link(_v);
            }
        }
        return res;
    }
};
int arr[100005];
int len[2000005];
int main()
{
    //freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
    int n;
        string s;
        cin>>s>>n;
		vector<string> t(n);
        for(int i=0;i<n;i++)
        {
        	cin>>arr[i]>>t[i];
        	len[i] = t[i].length();
		}

        vector<pii> res=Aho_Corasick(s,t).get();
       	vector<vi> ans(n);
        for(auto it: res)
			ans[it.se].pb(it.fi-t[it.se].length()+1);
        for(int i=0;i<n;i++)
		{
			int dap_ans = 1e9+7;
			for (int j = 0; j < ans[i].size() - arr[i] + 1; j++)
				dap_ans = min(dap_ans, ans[i][j+arr[i]-1] - ans[i][j] + len[i]);
			if (dap_ans == 1e9+7)
				dap_ans = -1;
			cout << dap_ans << endl;
		}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"

const int K=30;

struct Vertex {
    int next[K];
    bool leaf=false;
    int p=-1; char ch;
    int link=-1, slink=-1; int go[K];
    vi idx;
    Vertex(int p=-1, char ch='#'): p(p), ch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

struct Trie {
    vector<Vertex> trie; int n=0;
    void add(const string& s, int id) {
        int v=0;
        for(char ch: s) {
            int c=ch-32;
            if(trie[v].next[c]==-1) {
                trie[v].next[c]=trie.size();
                trie.emplace_back(v, ch);
            }
            v=trie[v].next[c];
        }
        trie[v].leaf=true;
        trie[v].idx.pb(id);
    }
    Trie() {trie=vector<Vertex>(1);}
    Trie(vector<string>& s) {trie=vector<Vertex>(1); for(string& it: s) add(it, n++);}
    int go(int v, char ch);
    int get_link(int v) {
        if(trie[v].link==-1) {
            if(v==0||trie[v].p==0) trie[v].link=0;
            else trie[v].link=go(get_link(trie[v].p), trie[v].ch);
        }
        return trie[v].link;
    }
    int get_suff_link(int v) {
        if(trie[v].slink==-1) {
            if(get_link(v)==0||trie[get_link(v)].leaf) trie[v].slink=get_link(v);
            else trie[v].slink=get_suff_link(get_link(v));
        }
        return trie[v].slink;
    }
};

int Trie::go(int v, char ch) {
    int c=ch-32;
    if(trie[v].go[c]==-1) {
        if(trie[v].next[c]!=-1) trie[v].go[c]=trie[v].next[c];
        else trie[v].go[c]=v==0?0:go(get_link(v), ch);
    }
    return trie[v].go[c];
}

struct Aho_Corasick {
    string s; Trie t;
    Aho_Corasick(string s, Trie t): s(s), t(t) {}
    Aho_Corasick(string s, vector<string>& vt): s(s), t(Trie(vt)) {}
    const vector<pii> get() {
        vector<pii> res;
        int v=0;
        for(int i=0;i<s.length();i++)
		{
            v=t.go(v, s[i]);
            int _v=v;
            while(_v!=0) {
                if(t.trie[_v].leaf) for(int id: t.trie[_v].idx) res.pb({i, id});
                _v=t.get_suff_link(_v);
            }
        }
        return res;
    }
};
int arr[100005];
int len[100005];
int main()
{
    //freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
    int n;
        string s;
        cin>>s>>n;
		vector<string> t(n);
        for(int i=0;i<n;i++)
        {
        	cin>>arr[i]>>t[i];
        	len[i] = t[i].length();
		}
        vector<pii> res=Aho_Corasick(s,t).get();
       	vector<vi> ans(n);
        for(auto it: res)
			ans[it.se].pb(it.fi-t[it.se].length()+1);
        for(int i=0;i<n;i++)
		{
			int dap_ans = 1e9+7;
			for (int j = 0; j < int(ans[i].size()) - arr[i] + 1; j++)
				dap_ans = min(dap_ans, ans[i][j+arr[i]-1] - ans[i][j] + len[i]);
			if (dap_ans == 1e9+7)
				dap_ans = -1;
			cout << dap_ans << endl;
		}

}


#include<bits/stdc++.h>
#define LL long long
#define int long long
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
struct lsg{int x,y,xx,yy,d;}a[100010],z[100010];
char s[100010],ss[100010];
int l,ll,p1,p2,q1[100010],q2[100010],f[100010],ff[100010],dd,n,faq[100010],ddd;
bool pd(lsg x,lsg y){return (x.y<y.y)||(x.y==y.y&&x.xx<y.xx)||(x.y==y.y&&x.xx==y.xx&&x.yy<y.yy);}
bool cmp(lsg x,lsg y){return (x.xx<y.xx)||(x.xx==y.xx&&x.yy<y.yy)||(x.xx==y.xx&&x.yy==y.yy&&x.x<y.x);}
void calc(int x){//处理出所有长度为x的字符串（的hash值
	for (int i=1;i+x-1<=l;i++){
		z[++dd].x=i;
		z[dd].xx=(f[i+x-1]-f[i-1]*q1[x]%p1+p1)%p1;
		z[dd].yy=(ff[i+x-1]-ff[i-1]*q2[x]%p2+p2)%p2;
	}
}
signed main(){
	scanf("%s",s+1);l=strlen(s+1);p1=998244353;p2=1e9+7;
	q1[0]=q2[0]=1;for (int i=1;i<=l;i++)q1[i]=q1[i-1]*29%p1,q2[i]=q2[i-1]*29%p2;
	for (int i=1;i<=l;i++)(f[i]=f[i-1]*29+s[i]-'a'+1)%=p1,(ff[i]=ff[i-1]*29+s[i]-'a'+1)%=p2;
	n=read();for (int i=1;i<=n;i++){
		a[i].x=read();scanf("%s",ss+1);
		a[i].y=strlen(ss+1);a[i].d=i;
		for (int j=1;j<=a[i].y;j++)(a[i].xx=a[i].xx*29+ss[j]-'a'+1)%=p1,(a[i].yy=a[i].yy*29+ss[j]-'a'+1)%=p2;
	}sort(a+1,a+1+n,pd);//第一关键字长度第二关键字hash值
	for (int i=1;i<=n;){
		dd=0;ddd=a[i].y;calc(a[i].y);
		sort(z+1,z+1+dd,cmp);//按hash值排序,起点位置为第二关键字
		for (int j=1;j<=dd;i++){
			if (ddd!=a[i].y)break;faq[a[i].d]=-1;
			while (j<=dd&&(z[j].xx<a[i].xx||z[j].xx==a[i].xx&&z[j].yy<a[i].yy))j++;
			if (z[j].xx!=a[i].xx&&z[j].yy!=a[i].yy)continue;
			int k=j;while (z[j].xx==z[k].xx&&z[j].yy==z[k].yy)k++;
			for (int qwq=j;qwq+a[i].x<=k;qwq++){
				if (faq[a[i].d]==-1)faq[a[i].d]=1e15;
				faq[a[i].d]=min(faq[a[i].d],z[qwq+a[i].x-1].x-z[qwq].x+ddd);
			}j=k;
		}
	}for (int i=1;i<=n;i++)writeln(faq[i]);
}
/*
aaabbbbaaabababab
4
2 aaabbbbaaaba
2 baaabab
1 abbbbaaabab
6 a
*/


#include<bits/stdc++.h>
#define LL long long
#define int long long
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
struct lsg{int x,y,xx,d;}a[100010],z[100010];
char s[100010],ss[100010];
int l,ll,q1[100010],f[100010],ff[100010],dd,n,faq[100010],ddd;
bool pd(lsg x,lsg y){return (x.y<y.y)||(x.y==y.y&&x.xx<y.xx);}
bool cmp(lsg x,lsg y){return (x.xx<y.xx)||(x.xx==y.xx&&x.x<y.x);}
void calc(int x){//处理出所有长度为x的字符串（的hash值
	for (int i=1;i+x-1<=l;i++){
		z[++dd].x=i;
		z[dd].xx=f[i+x-1]-f[i-1]*q1[x];
	}
}
signed main(){
	scanf("%s",s+1);l=strlen(s+1);
	q1[0]=1;for (int i=1;i<=l;i++)q1[i]=q1[i-1]*29;
	for (int i=1;i<=l;i++)f[i]=f[i-1]*29+s[i]-'a'+1;
	n=read();for (int i=1;i<=n;i++){
		a[i].x=read();scanf("%s",ss+1);
		a[i].y=strlen(ss+1);a[i].d=i;
		for (int j=1;j<=a[i].y;j++)a[i].xx=a[i].xx*29+ss[j]-'a'+1;
	}sort(a+1,a+1+n,pd);//第一关键字长度第二关键字hash值
	for (int i=1;i<=n;){
		dd=0;ddd=a[i].y;calc(a[i].y);
		sort(z+1,z+1+dd,cmp);//按hash值排序,起点位置为第二关键字
		for (int j=1;j<=dd;i++){
			if (ddd!=a[i].y)break;faq[a[i].d]=-1;
			while (j<=dd&&(z[j].xx<a[i].xx))j++;
			if (z[j].xx!=a[i].xx)continue;
			int k=j;while (z[j].xx==z[k].xx)k++;
			for (int qwq=j;qwq+a[i].x<=k;qwq++){
				if (faq[a[i].d]==-1)faq[a[i].d]=1e15;
				faq[a[i].d]=min(faq[a[i].d],z[qwq+a[i].x-1].x-z[qwq].x+ddd);
			}j=k;
		}
	}for (int i=1;i<=n;i++)writeln(faq[i]);
}
/*
aaabbbbaaabababab
4
2 aaabbbbaaaba
2 baaabab
1 abbbbaaabab
6 a
*/


#include<bits/stdc++.h>
#define LL long long
#define int long long
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
struct lsg{int x,y,xx,d;}a[100010];
char s[100010],ss[100010];
int l,ll,q1[100010],f[100010],ff[100010],dd,n,faq[100010],ddd,szb[100010],z[100010];
bool pd(lsg x,lsg y){return (x.y<y.y)||(x.y==y.y&&x.xx<y.xx);}
bool cmp(int x,int y){return (z[x]<z[y])||(z[x]==z[y]&&x<y);}
void calc(int x){//处理出所有长度为x的字符串（的hash值
	for (int i=1;i+x-1<=l;i++)z[++dd]=f[i+x-1]-f[i-1]*q1[x],szb[dd]=dd;
}
signed main(){
	scanf("%s",s+1);l=strlen(s+1);
	q1[0]=1;for (int i=1;i<=l;i++)q1[i]=q1[i-1]*29;
	for (int i=1;i<=l;i++)f[i]=f[i-1]*29+s[i]-'a'+1;
	n=read();for (int i=1;i<=n;i++){
		a[i].x=read();scanf("%s",ss+1);
		a[i].y=strlen(ss+1);a[i].d=i;
		for (int j=1;j<=a[i].y;j++)a[i].xx=a[i].xx*29+ss[j]-'a'+1;
	}sort(a+1,a+1+n,pd);//第一关键字长度第二关键字hash值
	for (int i=1;i<=n;){
		dd=0;ddd=a[i].y;calc(a[i].y);
		sort(szb+1,szb+1+dd,cmp);//按hash值排序,起点位置为第二关键字
		for (int j=1;j<=dd;i++){
			if (ddd!=a[i].y)break;faq[a[i].d]=-1;
			while (j<=dd&&(z[szb[j]]<a[i].xx))j++;
			if (z[szb[j]]!=a[i].xx)continue;
			int k=j;while (z[szb[j]]==z[szb[k]]&&k<=dd)k++;
			for (int qwq=j;qwq+a[i].x<=k;qwq++){
				if (faq[a[i].d]==-1)faq[a[i].d]=1e15;
				faq[a[i].d]=min(faq[a[i].d],szb[qwq+a[i].x-1]-szb[qwq]+ddd);
			}j=k;
		}
	}for (int i=1;i<=n;i++)writeln(faq[i]);
}
/*
aaabbbbaaabababab
4
2 aaabbbbaaaba
2 baaabab
1 abbbbaaabab
6 a
*/


#include<bits/stdc++.h>
#define LL long long
#define int long long
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
struct lsg{int x,y,xx,d;}a[100010];
char s[100010],ss[100010];
int l,ll,q1[100010],f[100010],ff[100010],dd,n,faq[100010],ddd,szb[100010],z[100010];
bool pd(lsg x,lsg y){return (x.y<y.y)||(x.y==y.y&&x.xx<y.xx);}
bool cmp(int x,int y){return (z[x]<z[y])||(z[x]==z[y]&&x<y);}
void calc(int x){//处理出所有长度为x的字符串（的hash值
	for (int i=1;i+x-1<=l;i++)z[++dd]=f[i+x-1]-f[i-1]*q1[x],szb[dd]=dd;
}
signed main(){
	scanf("%s",s+1);l=strlen(s+1);
	q1[0]=1;for (int i=1;i<=l;i++)q1[i]=q1[i-1]*29;
	for (int i=1;i<=l;i++)f[i]=f[i-1]*29+s[i]-'a'+1;
	n=read();for (int i=1;i<=n;i++){
		a[i].x=read();scanf("%s",ss+1);
		a[i].y=strlen(ss+1);a[i].d=i;
		for (int j=1;j<=a[i].y;j++)a[i].xx=a[i].xx*29+ss[j]-'a'+1;
	}sort(a+1,a+1+n,pd);//第一关键字长度第二关键字hash值
	for (int i=1;i<=n;){
		dd=0;ddd=a[i].y;calc(a[i].y);
		sort(szb+1,szb+1+dd,cmp);//按hash值排序,起点位置为第二关键字
		for (int j=1;j<=dd;i++){
			if (ddd!=a[i].y)break;faq[a[i].d]=-1;
			while (j<=dd&&(z[szb[j]]<a[i].xx))j++;
			if (z[szb[j]]!=a[i].xx)continue;
			int k=j;while (z[szb[j]]==z[szb[k]])k++;
			for (int qwq=j;qwq+a[i].x<=k;qwq++){
				if (faq[a[i].d]==-1)faq[a[i].d]=1e15;
				faq[a[i].d]=min(faq[a[i].d],szb[qwq+a[i].x-1]-szb[qwq]+ddd);
			}j=k;
		}
	}for (int i=1;i<=n;i++)writeln(faq[i]);
}
/*
aaabbbbaaabababab
4
2 aaabbbbaaaba
2 baaabab
1 abbbbaaabab
6 a
*/


#include<bits/stdc++.h>
#define LL int
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
struct lsg{int x,y,xx,d;}a[100010];
char s[100010],ss[100010];
int l,ll,q1[100010],f[100010],ff[100010],dd,n,faq[100010],ddd,szb[100010],z[100010];
vector<int> v[100010];
bool pd(lsg x,lsg y){return (x.y<y.y)||(x.y==y.y&&x.xx<y.xx);}
inline void calc(int x,int ll,int rr){
	for (int i=1;i+x-1<=l;i++){
		int ddd=f[i+x-1]-f[i-1]*q1[x],l=ll,r=rr;
		while (l<r){
			int m=(l+r)>>1;if (a[m].xx>=ddd)r=m;else l=m+1;
		}if (a[l].xx==ddd)v[l].push_back(i);
	}
}
signed main(){
	scanf("%s",s+1);l=strlen(s+1);
	q1[0]=1;for (int i=1;i<=l;i++)q1[i]=q1[i-1]*29;
	for (int i=1;i<=l;i++)f[i]=f[i-1]*29+s[i]-'a'+1;
	n=read();for (int i=1;i<=n;i++){
		a[i].x=read();scanf("%s",ss+1);a[i].y=strlen(ss+1);a[i].d=i;
		for (int j=1;j<=a[i].y;j++)a[i].xx=a[i].xx*29+ss[j]-'a'+1;
		faq[i]=1e9;
	}sort(a+1,a+1+n,pd);//第一关键字长度第二关键字hash值
	for (int i=1;i<=n;){
		dd=i;while (a[i].y==a[dd].y&&dd<=n)dd++;
		ddd=a[i].y;calc(a[i].y,i,dd-1);
		while (i<dd){
			int qwq=v[i].size();
			for (int k=0;k+a[i].x<=qwq;k++)faq[a[i].d]=min(faq[a[i].d],v[i][k+a[i].x-1]-v[i][k]+a[i].y);
			i++;
		}
	}for (int i=1;i<=n;i++)writeln(faq[i]==1000000000?-1:faq[i]);
}
/*
aaabbbbaaabababab
2
3 a
4 b
*/


#include<bits/stdc++.h>
#define LL int
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
struct lsg{int x,y,xx,d;}a[100010];
char s[100010],ss[100010];
int l,ll,q1[100010],f[100010],ff[100010],dd,n,faq[100010],ddd,szb[100010],z[100010];
vector<int> v[100010];
bool pd(lsg x,lsg y){return (x.y<y.y)||(x.y==y.y&&x.xx<y.xx);}
inline void calc(int x,int ll,int rr){
	for (int i=1;i+x-1<=l;i++){
		int ddd=f[i+x-1]-f[i-1]*q1[x],l=ll,r=rr;
		while (l<r){
			int m=(l+r)>>1;if (a[m].xx<=ddd)r=m;else l=m+1;
		}if (a[l].xx==ddd)v[l].push_back(i);
	}
}
signed main(){
	scanf("%s",s+1);l=strlen(s+1);
	q1[0]=1;for (int i=1;i<=l;i++)q1[i]=q1[i-1]*29;
	for (int i=1;i<=l;i++)f[i]=f[i-1]*29+s[i]-'a'+1;
	n=read();for (int i=1;i<=n;i++){
		a[i].x=read();scanf("%s",ss+1);a[i].y=strlen(ss+1);a[i].d=i;
		for (int j=1;j<=a[i].y;j++)a[i].xx=a[i].xx*29+ss[j]-'a'+1;
		faq[i]=1e9;
	}sort(a+1,a+1+n,pd);//第一关键字长度第二关键字hash值
	for (int i=1;i<=n;){
		dd=i;while (a[i].y==a[dd].y&&dd<=n)dd++;
		ddd=a[i].y;calc(a[i].y,i,dd-1);
		while (i<dd){
			int qwq=v[i].size();
			for (int k=0;k+a[i].x<=qwq;k++)faq[a[i].d]=min(faq[a[i].d],v[i][k+a[i].x-1]-v[i][k]+a[i].y);
			i++;
		}
	}for (int i=1;i<=n;i++)writeln(faq[i]==1000000000?-1:faq[i]);
}
/*
aaabbbbaaabababab
4
2 aaabbbbaaaba
2 baaabab
1 abbbbaaabab
6 a
*/


#include<bits/stdc++.h>
#define LL int
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
struct lsg{int x,y,xx,d;}a[100010];
char s[100010],ss[100010];
int l,ll,q1[100010],f[100010],ff[100010],dd,n,faq[100010],ddd,szb[100010],z[100010];
vector<int> v[100010];
bool pd(lsg x,lsg y){return (x.y<y.y)||(x.y==y.y&&x.xx<y.xx);}
inline void calc(int x,int ll,int rr){
	for (int i=1;i+x-1<=l;i++){
		int ddd=f[i+x-1]-f[i-1]*q1[x],l=ll,r=rr;
		while (l<r){
			int m=(l+r)>>1;if (a[m].xx<=ddd)r=m;else l=m+1;
		}if (a[l].xx==ddd)v[l].push_back(i);
	}
}
signed main(){
	scanf("%s",s+1);l=strlen(s+1);
	q1[0]=1;for (int i=1;i<=l;i++)q1[i]=q1[i-1]*29;
	for (int i=1;i<=l;i++)f[i]=f[i-1]*29+s[i]-'a'+1;
	n=read();for (int i=1;i<=n;i++){
		a[i].x=read();scanf("%s",ss+1);a[i].y=strlen(ss+1);a[i].d=i;
		for (int j=1;j<=a[i].y;j++)a[i].xx=a[i].xx*29+ss[j]-'a'+1;
		faq[i]=1e9;
	}sort(a+1,a+1+n,pd);//第一关键字长度第二关键字hash值
	for (int i=1;i<=n;){
		dd=i;while (a[i].xx==a[dd].xx&&dd<=n)dd++;
		ddd=a[i].y;calc(a[i].y,i,dd);
		while (i<dd){
			int qwq=v[i].size();
			for (int k=0;k+a[i].x<=qwq;k++)faq[a[i].d]=min(faq[a[i].d],v[i][k+a[i].x-1]-v[i][k]+a[i].y);
			i++;
		}
	}for (int i=1;i<=n;i++)writeln(faq[i]==1000000000?-1:faq[i]);
}
/*
aaabbbbaaabababab
4
2 aaabbbbaaaba
2 baaabab
1 abbbbaaabab
6 a
*/


#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
#define tget(i) ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0)
#define tset(i, b) t[(i) / 8] = (b) ? (mask[(i) % 8] | t[(i) / 8]) : ((~mask[(i) % 8]) & t[(i) / 8])
#define chr(i) (cs == sizeof(int) ? ((int*) s)[i] : ((unsigned char*) s)[i])
#define isLMS(i) (i > 0 && tget(i) && !tget(i - 1))
void getBuckets(unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    for (int i = 0; i <= K; i++) {
        bkt[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        bkt[chr(i)]++;
    }
    int sum = 0;
    for (int i = 0; i <= K; i++) {
        sum += bkt[i];
        bkt[i] = end ? sum : sum - bkt[i];
    }
}
void induceSAl(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = 0; i < n; i++) {
        int j = SA[i] - 1;
        if (j >= 0 && !tget(j)) {
            SA[bkt[chr(j)]++] = j;
        }
    }
}
void induceSAs(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = n - 1; i >= 0; i--) {
        int j = SA[i] - 1;
        if (j >= 0 && tget(j)) {
            SA[--bkt[chr(j)]] = j;
        }
    }
}
void buildSA(unsigned char* s, int* SA, int n, int K, int cs) {
    unsigned char* t = (unsigned char*) malloc(n / 8 + 1);
    tset(n - 2, 0);
    tset(n - 1, 1);
    for (int i = n - 3; i >= 0; i--) {
        tset(i, (chr(i) < chr(i + 1) || (chr(i) == chr(i + 1) && tget(i + 1) == 1)) ? 1 : 0);
    }
    int* bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, true);
    for (int i = 0; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = 1; i < n; i++) if (isLMS(i)) {
        SA[--bkt[chr(i)]] = i;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    int n1 = 0;
    for (int i = 0; i < n; i++) if (isLMS(SA[i])) {
        SA[n1++] = SA[i];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    int name = 0, prev = -1;
    for (int i = 0; i < n1; i++) {
        int pos = SA[i];
        int diff = 0;
        for (int d = 0; d < n; d++)
            if (prev == -1 || chr(pos + d) != chr(prev + d) || tget(pos + d) != tget(prev + d)) {
                diff = 1;
                break;
            }
            else if (d > 0 && (isLMS(pos + d) || isLMS(prev + d))) {
                break;
            }
        if (diff) {
            name++;
            prev = pos;
        }
        pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2;
        SA[n1 + pos] = name - 1;
    }
    for (int i = n - 1, j = n - 1; i >= n1; i--) if (SA[i] >= 0) {
        SA[j--] = SA[i];
    }
    int *SA1 = SA, *s1 = SA + n - n1;
    if (name < n1) {
        buildSA((unsigned char*) s1, SA1, n1, name - 1, sizeof(int));
    }
    else {
        for (int i = 0; i < n1; i++) {
            SA1[s1[i]] = i;
        }
    }
    bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, 1);
    for (int i = 1, j = 0; i < n; i++) if (isLMS(i)) {
        s1[j++] = i;
    }
    for (int i = 0; i < n1; i++) {
        SA1[i] = s1[SA1[i]];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = n1 - 1; i >= 0; i--) {
        int j = SA[i];
        SA[i] = -1;
        SA[--bkt[chr(j)]] = j;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    free(t);
}
struct SuffixArray {
    static const int MAXN = 3e5 + 5;
    static const int MAXC = 256;
    static const unsigned char SEP = '$';
    int SA[MAXN], RA[MAXN];
    int Phi[MAXN], PLCP[MAXN];
    int LCP[MAXN];
    int n;
    unsigned char s[MAXN];

    void build(char* t) {
        n = strlen(t);
        for (int i = 0; i < n; i++) {
            s[i] = t[i];
            RA[i] = SA[i] = 0;
            Phi[i] = PLCP[i] = LCP[i] = 0;
        }
        s[n] = 0;
        buildSA(s, SA, n, MAXC, 1);
        for (int i = 0; i < n; i++) {
            RA[SA[i]] = i;
        }
        buildLCP();
    }
    void buildLCP() {
        int L = 0;
        Phi[SA[0]] = -1;
        for (int i = 1; i < n; i++) Phi[SA[i]] = SA[i - 1];
        for (int i = 0; i < n; i++) {
            if (!~Phi[i]) {PLCP[i] = 0; continue;}
            while (s[i + L] == s[Phi[i] + L] && s[i + L] != SEP) L++;
            PLCP[i] = L;
            L = max(L - 1, 0);
        }
        for (int i = 0; i < n; i++) LCP[i] = PLCP[SA[i]];
    }
} sa;

template<class T, class cmp = less<T> > struct RMQ {
    int n;
    vector<T> a;
    vector<vector<T> > f;

    T best(T a, T b) {
        if (cmp()(a, b)) return a;
        return b;
    }
    void init(int n) {
        this->n = n;
        int p = 1; while ((1 << p) < n) p++;
        a.resize(n), f.resize(p + 1);
        for (int i = 0; i < (int) f.size(); i++) {
            f[i].resize(n);
        }
    }
    void upd(int u, T x) {
        a[u] = x;
    }
    void build() {
        for (int i = 0; i < n; i++) f[0][i] = a[i];
        for (int l = 0, k; (k = 1 << l) < n; l++) {
            for (int i = 0; i + k < n; i++) {
                f[l + 1][i] = best(f[l][i], f[l][i + k]);
            }
        }
    }
    T query(int a, int b) {
        int l = a == b ? 0 : __lg(b - a);
        return best(f[l][a], f[l][b - (1 << l) + 1]);
    }
};
RMQ<int> rmq;

const int maxn = 1e5 + 5;
string s, ss;
int n;
int k[maxn];
string t[maxn];
int pos[maxn];

int findprv(int t, int len) {
    int lo = 0, hi = t;
    while (lo < hi) {
        int mi = lo + hi >> 1;
        if (rmq.query(mi + 1, t) < len) {
            lo = mi + 1;
        }
        else {
            hi = mi;
        }
    }
    return lo + hi >> 1;
}
int findnxt(int t, int len) {
    int lo = t, hi = sz(ss) - 1;
    while (lo < hi) {
        int mi = lo + hi + 1 >> 1;
        if (rmq.query(t + 1, mi) >= len) {
            lo = mi;
        }
        else {
            hi = mi - 1;
        }
    }
    return lo + hi >> 1;
}

void chemthan() {
    cin >> s >> n;
    ss = s + "$";
    FOR(i, 0, n) {
        cin >> k[i] >> t[i];
        pos[i] = sz(ss);
        ss += t[i] + "$";
    }
    sa.build((char *) ss.data());
    rmq.init(sz(ss));
    FOR(i, 0, sz(ss)) {
        rmq.upd(i, sa.LCP[i]);
    }
    rmq.build();
    int cnt = 0;
    FOR(i, 0, n) {
        int x = pos[i];
        x = sa.RA[x];
        int lo = findprv(x, sz(t[i]));
        int hi = findnxt(x, sz(t[i]));
        static int vals[maxn];
        int num = 0;
        FOR(j, lo, hi + 1) {
            int p = sa.SA[j];
            if (p < sz(s)) {
                vals[num++] = p;
            }
            cnt++;
        }
        assert(cnt <= 100000000);
        if (num < k[i]) {
            cout << -1 << "\n";
            continue;
        }
        sort(vals, vals + num);
        int res = INF;
        FOR(j, 0, num - k[i] + 1) {
            chkmin(res, vals[j + k[i] - 1] - vals[j] + sz(t[i]));
        }
        cout << res << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
#define tget(i) ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0)
#define tset(i, b) t[(i) / 8] = (b) ? (mask[(i) % 8] | t[(i) / 8]) : ((~mask[(i) % 8]) & t[(i) / 8])
#define chr(i) (cs == sizeof(int) ? ((int*) s)[i] : ((unsigned char*) s)[i])
#define isLMS(i) (i > 0 && tget(i) && !tget(i - 1))
void getBuckets(unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    for (int i = 0; i <= K; i++) {
        bkt[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        bkt[chr(i)]++;
    }
    int sum = 0;
    for (int i = 0; i <= K; i++) {
        sum += bkt[i];
        bkt[i] = end ? sum : sum - bkt[i];
    }
}
void induceSAl(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = 0; i < n; i++) {
        int j = SA[i] - 1;
        if (j >= 0 && !tget(j)) {
            SA[bkt[chr(j)]++] = j;
        }
    }
}
void induceSAs(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = n - 1; i >= 0; i--) {
        int j = SA[i] - 1;
        if (j >= 0 && tget(j)) {
            SA[--bkt[chr(j)]] = j;
        }
    }
}
void buildSA(unsigned char* s, int* SA, int n, int K, int cs) {
    unsigned char* t = (unsigned char*) malloc(n / 8 + 1);
    tset(n - 2, 0);
    tset(n - 1, 1);
    for (int i = n - 3; i >= 0; i--) {
        tset(i, (chr(i) < chr(i + 1) || (chr(i) == chr(i + 1) && tget(i + 1) == 1)) ? 1 : 0);
    }
    int* bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, true);
    for (int i = 0; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = 1; i < n; i++) if (isLMS(i)) {
        SA[--bkt[chr(i)]] = i;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    int n1 = 0;
    for (int i = 0; i < n; i++) if (isLMS(SA[i])) {
        SA[n1++] = SA[i];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    int name = 0, prev = -1;
    for (int i = 0; i < n1; i++) {
        int pos = SA[i];
        int diff = 0;
        for (int d = 0; d < n; d++)
            if (prev == -1 || chr(pos + d) != chr(prev + d) || tget(pos + d) != tget(prev + d)) {
                diff = 1;
                break;
            }
            else if (d > 0 && (isLMS(pos + d) || isLMS(prev + d))) {
                break;
            }
        if (diff) {
            name++;
            prev = pos;
        }
        pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2;
        SA[n1 + pos] = name - 1;
    }
    for (int i = n - 1, j = n - 1; i >= n1; i--) if (SA[i] >= 0) {
        SA[j--] = SA[i];
    }
    int *SA1 = SA, *s1 = SA + n - n1;
    if (name < n1) {
        buildSA((unsigned char*) s1, SA1, n1, name - 1, sizeof(int));
    }
    else {
        for (int i = 0; i < n1; i++) {
            SA1[s1[i]] = i;
        }
    }
    bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, 1);
    for (int i = 1, j = 0; i < n; i++) if (isLMS(i)) {
        s1[j++] = i;
    }
    for (int i = 0; i < n1; i++) {
        SA1[i] = s1[SA1[i]];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = n1 - 1; i >= 0; i--) {
        int j = SA[i];
        SA[i] = -1;
        SA[--bkt[chr(j)]] = j;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    free(t);
}
struct SuffixArray {
    static const int MAXN = 3e5 + 5;
    static const int MAXC = 256;
    static const unsigned char SEP = '$';
    int SA[MAXN], RA[MAXN];
    int Phi[MAXN], PLCP[MAXN];
    int LCP[MAXN];
    int n;
    unsigned char s[MAXN];

    void build(char* t) {
        n = strlen(t);
        for (int i = 0; i < n; i++) {
            s[i] = t[i];
            RA[i] = SA[i] = 0;
            Phi[i] = PLCP[i] = LCP[i] = 0;
        }
        s[n] = 0;
        buildSA(s, SA, n, MAXC, 1);
        for (int i = 0; i < n; i++) {
            RA[SA[i]] = i;
        }
        buildLCP();
    }
    void buildLCP() {
        int L = 0;
        Phi[SA[0]] = -1;
        for (int i = 1; i < n; i++) Phi[SA[i]] = SA[i - 1];
        for (int i = 0; i < n; i++) {
            if (!~Phi[i]) {PLCP[i] = 0; continue;}
            while (s[i + L] == s[Phi[i] + L] && s[i + L] != SEP) L++;
            PLCP[i] = L;
            L = max(L - 1, 0);
        }
        for (int i = 0; i < n; i++) LCP[i] = PLCP[SA[i]];
    }
} sa;

template<class T, class cmp = less<T> > struct RMQ {
    int n;
    vector<T> a;
    vector<vector<T> > f;

    T best(T a, T b) {
        if (cmp()(a, b)) return a;
        return b;
    }
    void init(int n) {
        this->n = n;
        int p = 1; while ((1 << p) < n) p++;
        a.resize(n), f.resize(p + 1);
        for (int i = 0; i < (int) f.size(); i++) {
            f[i].resize(n);
        }
    }
    void upd(int u, T x) {
        a[u] = x;
    }
    void build() {
        for (int i = 0; i < n; i++) f[0][i] = a[i];
        for (int l = 0, k; (k = 1 << l) < n; l++) {
            for (int i = 0; i + k < n; i++) {
                f[l + 1][i] = best(f[l][i], f[l][i + k]);
            }
        }
    }
    T query(int a, int b) {
        int l = a == b ? 0 : __lg(b - a);
        return best(f[l][a], f[l][b - (1 << l) + 1]);
    }
};
RMQ<int> rmq;

const int maxn = 1e5 + 5;
string s, ss;
int n;
int k[maxn];
string t[maxn];
int pos[maxn];

int findprv(int t, int len) {
    int lo = 0, hi = t;
    while (lo < hi) {
        int mi = lo + hi >> 1;
        if (rmq.query(mi + 1, t) < len) {
            lo = mi + 1;
        }
        else {
            hi = mi;
        }
    }
    return lo + hi >> 1;
}
int findnxt(int t, int len) {
    int lo = t, hi = sz(ss) - 1;
    while (lo < hi) {
        int mi = lo + hi + 1 >> 1;
        if (rmq.query(t + 1, mi) >= len) {
            lo = mi;
        }
        else {
            hi = mi - 1;
        }
    }
    return lo + hi >> 1;
}

void chemthan() {
    cin >> s >> n;
    ss = s + "$";
    FOR(i, 0, n) {
        cin >> k[i] >> t[i];
        pos[i] = sz(ss);
        ss += t[i] + "$";
    }
    sa.build((char *) ss.data());
    rmq.init(sz(ss));
    FOR(i, 0, sz(ss)) {
        rmq.upd(i, sa.LCP[i]);
    }
    rmq.build();
    int cnt = 0;
    FOR(i, 0, n) {
        int x = pos[i];
        x = sa.RA[x];
        int lo = findprv(x, sz(t[i]));
        int hi = findnxt(x, sz(t[i]));
        static int vals[maxn];
        int num = 0;
        FOR(j, lo, hi + 1) {
            int p = sa.SA[j];
            if (p < sz(s)) {
                vals[num++] = p;
            }
            cnt++;
        }
        assert(cnt <= 200000);
        if (num < k[i]) {
            cout << -1 << "\n";
            continue;
        }
        sort(vals, vals + num);
        int res = INF;
        FOR(j, 0, num - k[i] + 1) {
            chkmin(res, vals[j + k[i] - 1] - vals[j] + sz(t[i]));
        }
        cout << res << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
#define tget(i) ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0)
#define tset(i, b) t[(i) / 8] = (b) ? (mask[(i) % 8] | t[(i) / 8]) : ((~mask[(i) % 8]) & t[(i) / 8])
#define chr(i) (cs == sizeof(int) ? ((int*) s)[i] : ((unsigned char*) s)[i])
#define isLMS(i) (i > 0 && tget(i) && !tget(i - 1))
void getBuckets(unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    for (int i = 0; i <= K; i++) {
        bkt[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        bkt[chr(i)]++;
    }
    int sum = 0;
    for (int i = 0; i <= K; i++) {
        sum += bkt[i];
        bkt[i] = end ? sum : sum - bkt[i];
    }
}
void induceSAl(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = 0; i < n; i++) {
        int j = SA[i] - 1;
        if (j >= 0 && !tget(j)) {
            SA[bkt[chr(j)]++] = j;
        }
    }
}
void induceSAs(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = n - 1; i >= 0; i--) {
        int j = SA[i] - 1;
        if (j >= 0 && tget(j)) {
            SA[--bkt[chr(j)]] = j;
        }
    }
}
void buildSA(unsigned char* s, int* SA, int n, int K, int cs) {
    unsigned char* t = (unsigned char*) malloc(n / 8 + 1);
    tset(n - 2, 0);
    tset(n - 1, 1);
    for (int i = n - 3; i >= 0; i--) {
        tset(i, (chr(i) < chr(i + 1) || (chr(i) == chr(i + 1) && tget(i + 1) == 1)) ? 1 : 0);
    }
    int* bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, true);
    for (int i = 0; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = 1; i < n; i++) if (isLMS(i)) {
        SA[--bkt[chr(i)]] = i;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    int n1 = 0;
    for (int i = 0; i < n; i++) if (isLMS(SA[i])) {
        SA[n1++] = SA[i];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    int name = 0, prev = -1;
    for (int i = 0; i < n1; i++) {
        int pos = SA[i];
        int diff = 0;
        for (int d = 0; d < n; d++)
            if (prev == -1 || chr(pos + d) != chr(prev + d) || tget(pos + d) != tget(prev + d)) {
                diff = 1;
                break;
            }
            else if (d > 0 && (isLMS(pos + d) || isLMS(prev + d))) {
                break;
            }
        if (diff) {
            name++;
            prev = pos;
        }
        pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2;
        SA[n1 + pos] = name - 1;
    }
    for (int i = n - 1, j = n - 1; i >= n1; i--) if (SA[i] >= 0) {
        SA[j--] = SA[i];
    }
    int *SA1 = SA, *s1 = SA + n - n1;
    if (name < n1) {
        buildSA((unsigned char*) s1, SA1, n1, name - 1, sizeof(int));
    }
    else {
        for (int i = 0; i < n1; i++) {
            SA1[s1[i]] = i;
        }
    }
    bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, 1);
    for (int i = 1, j = 0; i < n; i++) if (isLMS(i)) {
        s1[j++] = i;
    }
    for (int i = 0; i < n1; i++) {
        SA1[i] = s1[SA1[i]];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = n1 - 1; i >= 0; i--) {
        int j = SA[i];
        SA[i] = -1;
        SA[--bkt[chr(j)]] = j;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    free(t);
}
struct SuffixArray {
    static const int MAXN = 3e5 + 5;
    static const int MAXC = 256;
    static const unsigned char SEP = '$';
    int SA[MAXN], RA[MAXN];
    int Phi[MAXN], PLCP[MAXN];
    int LCP[MAXN];
    int n;
    unsigned char s[MAXN];

    void build(char* t) {
        n = strlen(t);
        for (int i = 0; i < n; i++) {
            s[i] = t[i];
            RA[i] = SA[i] = 0;
            Phi[i] = PLCP[i] = LCP[i] = 0;
        }
        s[n] = 0;
        buildSA(s, SA, n, MAXC, 1);
        for (int i = 0; i < n; i++) {
            RA[SA[i]] = i;
        }
        buildLCP();
    }
    void buildLCP() {
        int L = 0;
        Phi[SA[0]] = -1;
        for (int i = 1; i < n; i++) Phi[SA[i]] = SA[i - 1];
        for (int i = 0; i < n; i++) {
            if (!~Phi[i]) {PLCP[i] = 0; continue;}
            while (s[i + L] == s[Phi[i] + L] && s[i + L] != SEP) L++;
            PLCP[i] = L;
            L = max(L - 1, 0);
        }
        for (int i = 0; i < n; i++) LCP[i] = PLCP[SA[i]];
    }
} sa;

template<class T, class cmp = less<T> > struct RMQ {
    int n;
    vector<T> a;
    vector<vector<T> > f;

    T best(T a, T b) {
        if (cmp()(a, b)) return a;
        return b;
    }
    void init(int n) {
        this->n = n;
        int p = 1; while ((1 << p) < n) p++;
        a.resize(n), f.resize(p + 1);
        for (int i = 0; i < (int) f.size(); i++) {
            f[i].resize(n);
        }
    }
    void upd(int u, T x) {
        a[u] = x;
    }
    void build() {
        for (int i = 0; i < n; i++) f[0][i] = a[i];
        for (int l = 0, k; (k = 1 << l) < n; l++) {
            for (int i = 0; i + k < n; i++) {
                f[l + 1][i] = best(f[l][i], f[l][i + k]);
            }
        }
    }
    T query(int a, int b) {
        int l = a == b ? 0 : __lg(b - a);
        return best(f[l][a], f[l][b - (1 << l) + 1]);
    }
};
RMQ<int> rmq;

const int maxn = 1e5 + 5;
string s, ss;
int n;
int k[maxn];
string t[maxn];
int pos[maxn];

int findprv(int t, int len) {
    int lo = 0, hi = t;
    while (lo < hi) {
        int mi = lo + hi >> 1;
        if (rmq.query(mi + 1, t) < len) {
            lo = mi + 1;
        }
        else {
            hi = mi;
        }
    }
    return lo + hi >> 1;
}
int findnxt(int t, int len) {
    int lo = t, hi = sz(ss) - 1;
    while (lo < hi) {
        int mi = lo + hi + 1 >> 1;
        if (rmq.query(t + 1, mi) >= len) {
            lo = mi;
        }
        else {
            hi = mi - 1;
        }
    }
    return lo + hi >> 1;
}

void chemthan() {
    cin >> s >> n;
    ss = s + "$";
    FOR(i, 0, n) {
        cin >> k[i] >> t[i];
        pos[i] = sz(ss);
        ss += t[i] + "$";
    }
    sa.build((char *) ss.data());
    rmq.init(sz(ss));
    FOR(i, 0, sz(ss)) {
        rmq.upd(i, sa.LCP[i]);
    }
    rmq.build();
    int cnt = 0;
    FOR(i, 0, n) {
        int x = pos[i];
        x = sa.RA[x];
        int lo = findprv(x, sz(t[i]));
        int hi = findnxt(x, sz(t[i]));
        static int vals[maxn];
        int num = 0;
        FOR(j, lo, hi + 1) {
            int p = sa.SA[j];
            if (p < sz(s)) {
                vals[num++] = p;
            }
            cnt++;
        }
        assert(cnt <= 1000000);
        if (num < k[i]) {
            cout << -1 << "\n";
            continue;
        }
        sort(vals, vals + num);
        int res = INF;
        FOR(j, 0, num - k[i] + 1) {
            chkmin(res, vals[j + k[i] - 1] - vals[j] + sz(t[i]));
        }
        cout << res << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const long long MAXN = 100005;
const long long mod = 1e9+9;
string s;
pair<long long,long long> que[MAXN];
vector<pair<long long,long long> > pos[MAXN];
vector<long long> occ[MAXN];
long long pw[MAXN],H[MAXN];
long long ans[MAXN];
void fill_hash(string &s,long long hash[MAXN],long long MOD){
    hash[0] = s[0];
    for(long long i = 1; i < s.size(); i++){ hash[i] = (hash[i-1] * 256 + s[i]) % MOD;}
}
long long get_range(long long p,long long len,long long hash[MAXN],long long MOD){
    if(p == 0) return hash[len-1];
    long long R = hash[p + len - 1];
    long long L = (hash[p - 1] * pw[len]) % MOD;
    return (R - L + MOD) % MOD;
}
long long getHash(string &s){
    long long res = 0;
    for(long long i = 0; i < s.size(); i++) res = (res * 256 + s[i]) % mod;
    return (long long)res;
}
string cand[100005];
int main(){
    memset(ans,-1,sizeof(ans));
    cin >> s;
    long long q; cin >> q;
    pw[0] = 1;
    for(long long i = 1; i < MAXN; i++) pw[i] = (pw[i-1] * 256) % mod;
    for(long long i = 1; i <= q; i++){
        cin >> que[i].second >> cand[i];
        que[i].first = getHash(cand[i]);
        pos[cand[i].size()].push_back(make_pair(que[i].first,i));
    }
    fill_hash(s,H,mod);
    for(long long i = 1; i <= s.size(); i++){
        if(pos[i].size() == 0) continue;
        sort(pos[i].begin(),pos[i].end());
        for(long long j = 0; j < s.size(); j++){
            if(j + i > s.size()) break;
            long long hat = get_range(j,i,H,mod);
            auto it = lower_bound(pos[i].begin(),pos[i].end(),make_pair(hat,(long long)-1));
            if(it == pos[i].end()) continue;
            occ[it->second].push_back(j);
        }
    }
    for(long long i = 1; i <= q; i++){
        if(occ[i].size() < que[i].second) continue;
        for(long long j = 0; j + que[i].second <= occ[i].size(); j++){
            long long l = occ[i][j];
            long long r = occ[i][j+que[i].second - 1];
            if(ans[i] == -1) ans[i] = r - l + cand[i].size();
            else ans[i] = min(ans[i],r - l + (long long)cand[i].size());
        }
    }
    for(long long i = 1; i <= q; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
#define tget(i) ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0)
#define tset(i, b) t[(i) / 8] = (b) ? (mask[(i) % 8] | t[(i) / 8]) : ((~mask[(i) % 8]) & t[(i) / 8])
#define chr(i) (cs == sizeof(int) ? ((int*) s)[i] : ((unsigned char*) s)[i])
#define isLMS(i) (i > 0 && tget(i) && !tget(i - 1))
void getBuckets(unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    for (int i = 0; i <= K; i++) {
        bkt[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        bkt[chr(i)]++;
    }
    int sum = 0;
    for (int i = 0; i <= K; i++) {
        sum += bkt[i];
        bkt[i] = end ? sum : sum - bkt[i];
    }
}
void induceSAl(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = 0; i < n; i++) {
        int j = SA[i] - 1;
        if (j >= 0 && !tget(j)) {
            SA[bkt[chr(j)]++] = j;
        }
    }
}
void induceSAs(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = n - 1; i >= 0; i--) {
        int j = SA[i] - 1;
        if (j >= 0 && tget(j)) {
            SA[--bkt[chr(j)]] = j;
        }
    }
}
void buildSA(unsigned char* s, int* SA, int n, int K, int cs) {
    unsigned char* t = (unsigned char*) malloc(n / 8 + 1);
    tset(n - 2, 0);
    tset(n - 1, 1);
    for (int i = n - 3; i >= 0; i--) {
        tset(i, (chr(i) < chr(i + 1) || (chr(i) == chr(i + 1) && tget(i + 1) == 1)) ? 1 : 0);
    }
    int* bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, true);
    for (int i = 0; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = 1; i < n; i++) if (isLMS(i)) {
        SA[--bkt[chr(i)]] = i;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    int n1 = 0;
    for (int i = 0; i < n; i++) if (isLMS(SA[i])) {
        SA[n1++] = SA[i];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    int name = 0, prev = -1;
    for (int i = 0; i < n1; i++) {
        int pos = SA[i];
        int diff = 0;
        for (int d = 0; d < n; d++)
            if (prev == -1 || chr(pos + d) != chr(prev + d) || tget(pos + d) != tget(prev + d)) {
                diff = 1;
                break;
            }
            else if (d > 0 && (isLMS(pos + d) || isLMS(prev + d))) {
                break;
            }
        if (diff) {
            name++;
            prev = pos;
        }
        pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2;
        SA[n1 + pos] = name - 1;
    }
    for (int i = n - 1, j = n - 1; i >= n1; i--) if (SA[i] >= 0) {
        SA[j--] = SA[i];
    }
    int *SA1 = SA, *s1 = SA + n - n1;
    if (name < n1) {
        buildSA((unsigned char*) s1, SA1, n1, name - 1, sizeof(int));
    }
    else {
        for (int i = 0; i < n1; i++) {
            SA1[s1[i]] = i;
        }
    }
    bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, 1);
    for (int i = 1, j = 0; i < n; i++) if (isLMS(i)) {
        s1[j++] = i;
    }
    for (int i = 0; i < n1; i++) {
        SA1[i] = s1[SA1[i]];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = n1 - 1; i >= 0; i--) {
        int j = SA[i];
        SA[i] = -1;
        SA[--bkt[chr(j)]] = j;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    free(t);
}
struct SuffixArray {
    static const int MAXN = 3e5 + 5;
    static const int MAXC = 256;
    static const unsigned char SEP = '$';
    int SA[MAXN], RA[MAXN];
    int Phi[MAXN], PLCP[MAXN];
    int LCP[MAXN];
    int n;
    unsigned char s[MAXN];

    void build(char* t) {
        n = strlen(t);
        for (int i = 0; i < n; i++) {
            s[i] = t[i];
            RA[i] = SA[i] = 0;
            Phi[i] = PLCP[i] = LCP[i] = 0;
        }
        s[n] = 0;
        buildSA(s, SA, n, MAXC, 1);
        for (int i = 0; i < n; i++) {
            RA[SA[i]] = i;
        }
        buildLCP();
    }
    void buildLCP() {
        int L = 0;
        Phi[SA[0]] = -1;
        for (int i = 1; i < n; i++) Phi[SA[i]] = SA[i - 1];
        for (int i = 0; i < n; i++) {
            if (!~Phi[i]) {PLCP[i] = 0; continue;}
            while (s[i + L] == s[Phi[i] + L] && s[i + L] != SEP) L++;
            PLCP[i] = L;
            L = max(L - 1, 0);
        }
        for (int i = 0; i < n; i++) LCP[i] = PLCP[SA[i]];
    }
} sa;

template<class T, class cmp = less<T> > struct RMQ {
    int n;
    vector<T> a;
    vector<vector<T> > f;

    T best(T a, T b) {
        if (cmp()(a, b)) return a;
        return b;
    }
    void init(int n) {
        this->n = n;
        int p = 1; while ((1 << p) < n) p++;
        a.resize(n), f.resize(p + 1);
        for (int i = 0; i < (int) f.size(); i++) {
            f[i].resize(n);
        }
    }
    void upd(int u, T x) {
        a[u] = x;
    }
    void build() {
        for (int i = 0; i < n; i++) f[0][i] = a[i];
        for (int l = 0, k; (k = 1 << l) < n; l++) {
            for (int i = 0; i + k < n; i++) {
                f[l + 1][i] = best(f[l][i], f[l][i + k]);
            }
        }
    }
    T query(int a, int b) {
        int l = a == b ? 0 : __lg(b - a);
        return best(f[l][a], f[l][b - (1 << l) + 1]);
    }
};
RMQ<int> rmq;

const int maxn = 1e5 + 5;
string s, ss;
int n;
int k[maxn];
string t[maxn];
int pos[maxn];

int findprv(int t, int len) {
    int lo = 0, hi = t;
    while (lo < hi) {
        int mi = lo + hi >> 1;
        if (rmq.query(mi + 1, t) < len) {
            lo = mi + 1;
        }
        else {
            hi = mi;
        }
    }
    return lo + hi >> 1;
}
int findnxt(int t, int len) {
    int lo = t, hi = sz(ss) - 1;
    while (lo < hi) {
        int mi = lo + hi + 1 >> 1;
        if (rmq.query(t + 1, mi) >= len) {
            lo = mi;
        }
        else {
            hi = mi - 1;
        }
    }
    return lo + hi >> 1;
}

void chemthan() {
    cin >> s >> n;
    ss = s + "$";
    FOR(i, 0, n) {
        cin >> k[i] >> t[i];
        pos[i] = sz(ss);
        ss += t[i] + "$";
    }
    sa.build((char *) ss.data());
    rmq.init(sz(ss));
    FOR(i, 0, sz(ss)) {
        rmq.upd(i, sa.LCP[i]);
    }
    rmq.build();
    int cnt = 0;
    FOR(i, 0, n) {
        int x = pos[i];
        x = sa.RA[x];
        int lo = findprv(x, sz(t[i]));
        int hi = findnxt(x, sz(t[i]));
        static int vals[maxn];
        int num = 0;
        FOR(j, lo, hi + 1) {
            int p = sa.SA[j];
            if (p < sz(s)) {
                vals[num++] = p;
            }
            cnt++;
        }
        assert(cnt <= 5000000);
        if (num < k[i]) {
            cout << -1 << "\n";
            continue;
        }
        sort(vals, vals + num);
        int res = INF;
        FOR(j, 0, num - k[i] + 1) {
            chkmin(res, vals[j + k[i] - 1] - vals[j] + sz(t[i]));
        }
        cout << res << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 100005;
const int mod = 1e9+223;
string s;
pair<int,int> que[MAXN];
vector<pair<int,int> > pos[MAXN];
vector<int> occ[MAXN];
long long pw[MAXN],H[MAXN];
int ans[MAXN];
void fill_hash(string &s,long long hash[MAXN],long long MOD){
    hash[0] = s[0];
    for(int i = 1; i < s.size(); i++){ hash[i] = (hash[i-1] * 256 + s[i]) % MOD;}
}
int get_range(int p,int len,long long hash[MAXN],long long MOD){
    if(p == 0) return hash[len-1];
    int R = hash[p + len - 1];
    int L = (hash[p - 1] * pw[len]) % MOD;
    return (R - L + MOD) % MOD;
}
int getHash(string &s){
    long long res = 0;
    for(int i = 0; i < s.size(); i++) res = (res * 256 + s[i]) % mod;
    return (int)res;
}
string cand[100005];
int main(){
    memset(ans,-1,sizeof(ans));
    cin >> s;
    int q; cin >> q;
    pw[0] = 1;
    for(int i = 1; i < MAXN; i++) pw[i] = (pw[i-1] * 256) % mod;
    for(int i = 1; i <= q; i++){
        cin >> que[i].second >> cand[i];
        que[i].first = getHash(cand[i]);
        pos[cand[i].size()].push_back(make_pair(que[i].first,i));
    }
    fill_hash(s,H,mod);
    for(int i = 1; i <= s.size(); i++){
        if(pos[i].size() == 0) continue;
        sort(pos[i].begin(),pos[i].end());
        for(int j = 0; j < s.size(); j++){
            if(j + i > s.size()) break;
            int hat = get_range(j,i,H,mod);
            auto it = lower_bound(pos[i].begin(),pos[i].end(),make_pair(hat,-1));
            if(it == pos[i].end()) continue;
            if(it->first == hat){
                occ[it->second].push_back(j);
            }
        }
    }
    for(int i = 1; i <= q; i++){
        if(occ[i].size() < que[i].second) continue;
        for(int j = 0; j + que[i].second <= occ[i].size(); j++){
            int l = occ[i][j];
            int r = occ[i][j+que[i].second - 1];
            if(ans[i] == -1) ans[i] = r - l + cand[i].size();
            else ans[i] = min(ans[i],r - l + (int)cand[i].size());
        }
    }
    for(int i = 1; i <= q; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
#define tget(i) ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0)
#define tset(i, b) t[(i) / 8] = (b) ? (mask[(i) % 8] | t[(i) / 8]) : ((~mask[(i) % 8]) & t[(i) / 8])
#define chr(i) (cs == sizeof(int) ? ((int*) s)[i] : ((unsigned char*) s)[i])
#define isLMS(i) (i > 0 && tget(i) && !tget(i - 1))
void getBuckets(unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    for (int i = 0; i <= K; i++) {
        bkt[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        bkt[chr(i)]++;
    }
    int sum = 0;
    for (int i = 0; i <= K; i++) {
        sum += bkt[i];
        bkt[i] = end ? sum : sum - bkt[i];
    }
}
void induceSAl(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = 0; i < n; i++) {
        int j = SA[i] - 1;
        if (j >= 0 && !tget(j)) {
            SA[bkt[chr(j)]++] = j;
        }
    }
}
void induceSAs(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = n - 1; i >= 0; i--) {
        int j = SA[i] - 1;
        if (j >= 0 && tget(j)) {
            SA[--bkt[chr(j)]] = j;
        }
    }
}
void buildSA(unsigned char* s, int* SA, int n, int K, int cs) {
    unsigned char* t = (unsigned char*) malloc(n / 8 + 1);
    tset(n - 2, 0);
    tset(n - 1, 1);
    for (int i = n - 3; i >= 0; i--) {
        tset(i, (chr(i) < chr(i + 1) || (chr(i) == chr(i + 1) && tget(i + 1) == 1)) ? 1 : 0);
    }
    int* bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, true);
    for (int i = 0; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = 1; i < n; i++) if (isLMS(i)) {
        SA[--bkt[chr(i)]] = i;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    int n1 = 0;
    for (int i = 0; i < n; i++) if (isLMS(SA[i])) {
        SA[n1++] = SA[i];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    int name = 0, prev = -1;
    for (int i = 0; i < n1; i++) {
        int pos = SA[i];
        int diff = 0;
        for (int d = 0; d < n; d++)
            if (prev == -1 || chr(pos + d) != chr(prev + d) || tget(pos + d) != tget(prev + d)) {
                diff = 1;
                break;
            }
            else if (d > 0 && (isLMS(pos + d) || isLMS(prev + d))) {
                break;
            }
        if (diff) {
            name++;
            prev = pos;
        }
        pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2;
        SA[n1 + pos] = name - 1;
    }
    for (int i = n - 1, j = n - 1; i >= n1; i--) if (SA[i] >= 0) {
        SA[j--] = SA[i];
    }
    int *SA1 = SA, *s1 = SA + n - n1;
    if (name < n1) {
        buildSA((unsigned char*) s1, SA1, n1, name - 1, sizeof(int));
    }
    else {
        for (int i = 0; i < n1; i++) {
            SA1[s1[i]] = i;
        }
    }
    bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, 1);
    for (int i = 1, j = 0; i < n; i++) if (isLMS(i)) {
        s1[j++] = i;
    }
    for (int i = 0; i < n1; i++) {
        SA1[i] = s1[SA1[i]];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = n1 - 1; i >= 0; i--) {
        int j = SA[i];
        SA[i] = -1;
        SA[--bkt[chr(j)]] = j;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    free(t);
}
struct SuffixArray {
    static const int MAXN = 3e5 + 5;
    static const int MAXC = 256;
    static const unsigned char SEP = '$';
    int SA[MAXN], RA[MAXN];
    int Phi[MAXN], PLCP[MAXN];
    int LCP[MAXN];
    int n;
    unsigned char s[MAXN];

    void build(char* t) {
        n = strlen(t);
        for (int i = 0; i < n; i++) {
            s[i] = t[i];
            RA[i] = SA[i] = 0;
            Phi[i] = PLCP[i] = LCP[i] = 0;
        }
        s[n] = 0;
        buildSA(s, SA, n, MAXC, 1);
        for (int i = 0; i < n; i++) {
            RA[SA[i]] = i;
        }
        buildLCP();
    }
    void buildLCP() {
        int L = 0;
        Phi[SA[0]] = -1;
        for (int i = 1; i < n; i++) Phi[SA[i]] = SA[i - 1];
        for (int i = 0; i < n; i++) {
            if (!~Phi[i]) {PLCP[i] = 0; continue;}
            while (s[i + L] == s[Phi[i] + L] && s[i + L] != SEP) L++;
            PLCP[i] = L;
            L = max(L - 1, 0);
        }
        for (int i = 0; i < n; i++) LCP[i] = PLCP[SA[i]];
    }
} sa;

template<class T, class cmp = less<T> > struct RMQ {
    int n;
    vector<T> a;
    vector<vector<T> > f;

    T best(T a, T b) {
        if (cmp()(a, b)) return a;
        return b;
    }
    void init(int n) {
        this->n = n;
        int p = 1; while ((1 << p) < n) p++;
        a.resize(n), f.resize(p + 1);
        for (int i = 0; i < (int) f.size(); i++) {
            f[i].resize(n);
        }
    }
    void upd(int u, T x) {
        a[u] = x;
    }
    void build() {
        for (int i = 0; i < n; i++) f[0][i] = a[i];
        for (int l = 0, k; (k = 1 << l) < n; l++) {
            for (int i = 0; i + k < n; i++) {
                f[l + 1][i] = best(f[l][i], f[l][i + k]);
            }
        }
    }
    T query(int a, int b) {
        int l = a == b ? 0 : __lg(b - a);
        return best(f[l][a], f[l][b - (1 << l) + 1]);
    }
};
RMQ<int> rmq;

const int maxn = 1e5 + 5;
string s, ss;
int n;
int k[maxn];
string t[maxn];
int pos[maxn];

int findprv(int t, int len) {
    int lo = 0, hi = t;
    while (lo < hi) {
        int mi = lo + hi >> 1;
        if (rmq.query(mi + 1, t) < len) {
            lo = mi + 1;
        }
        else {
            hi = mi;
        }
    }
    return lo + hi >> 1;
}
int findnxt(int t, int len) {
    int lo = t, hi = sz(ss) - 1;
    while (lo < hi) {
        int mi = lo + hi + 1 >> 1;
        if (rmq.query(t + 1, mi) >= len) {
            lo = mi;
        }
        else {
            hi = mi - 1;
        }
    }
    return lo + hi >> 1;
}

void chemthan() {
    cin >> s >> n;
    ss = s + "$";
    FOR(i, 0, n) {
        cin >> k[i] >> t[i];
        pos[i] = sz(ss);
        ss += t[i] + "$";
    }
    sa.build((char *) ss.data());
    rmq.init(sz(ss));
    FOR(i, 0, sz(ss)) {
        rmq.upd(i, sa.LCP[i]);
    }
    rmq.build();
    int cnt = 0;
    FOR(i, 0, n) {
        int x = pos[i];
        x = sa.RA[x];
        int lo = findprv(x, sz(t[i]));
        int hi = findnxt(x, sz(t[i]));
        static int vals[maxn];
        int num = 0;
        FOR(j, lo, hi + 1) {
            int p = sa.SA[j];
            if (p < sz(s)) {
                vals[num++] = p;
            }
            cnt++;
        }
        assert(cnt <= 10000000);
        if (num < k[i]) {
            cout << -1 << "\n";
            continue;
        }
        sort(vals, vals + num);
        int res = INF;
        FOR(j, 0, num - k[i] + 1) {
            chkmin(res, vals[j + k[i] - 1] - vals[j] + sz(t[i]));
        }
        cout << res << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
#define tget(i) ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0)
#define tset(i, b) t[(i) / 8] = (b) ? (mask[(i) % 8] | t[(i) / 8]) : ((~mask[(i) % 8]) & t[(i) / 8])
#define chr(i) (cs == sizeof(int) ? ((int*) s)[i] : ((unsigned char*) s)[i])
#define isLMS(i) (i > 0 && tget(i) && !tget(i - 1))
void getBuckets(unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    for (int i = 0; i <= K; i++) {
        bkt[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        bkt[chr(i)]++;
    }
    int sum = 0;
    for (int i = 0; i <= K; i++) {
        sum += bkt[i];
        bkt[i] = end ? sum : sum - bkt[i];
    }
}
void induceSAl(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = 0; i < n; i++) {
        int j = SA[i] - 1;
        if (j >= 0 && !tget(j)) {
            SA[bkt[chr(j)]++] = j;
        }
    }
}
void induceSAs(unsigned char* t, int* SA, unsigned char* s, int* bkt, int n, int K, int cs, int end) {
    getBuckets(s, bkt, n, K, cs, end);
    for (int i = n - 1; i >= 0; i--) {
        int j = SA[i] - 1;
        if (j >= 0 && tget(j)) {
            SA[--bkt[chr(j)]] = j;
        }
    }
}
void buildSA(unsigned char* s, int* SA, int n, int K, int cs) {
    unsigned char* t = (unsigned char*) malloc(n / 8 + 1);
    tset(n - 2, 0);
    tset(n - 1, 1);
    for (int i = n - 3; i >= 0; i--) {
        tset(i, (chr(i) < chr(i + 1) || (chr(i) == chr(i + 1) && tget(i + 1) == 1)) ? 1 : 0);
    }
    int* bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, true);
    for (int i = 0; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = 1; i < n; i++) if (isLMS(i)) {
        SA[--bkt[chr(i)]] = i;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    int n1 = 0;
    for (int i = 0; i < n; i++) if (isLMS(SA[i])) {
        SA[n1++] = SA[i];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    int name = 0, prev = -1;
    for (int i = 0; i < n1; i++) {
        int pos = SA[i];
        int diff = 0;
        for (int d = 0; d < n; d++)
            if (prev == -1 || chr(pos + d) != chr(prev + d) || tget(pos + d) != tget(prev + d)) {
                diff = 1;
                break;
            }
            else if (d > 0 && (isLMS(pos + d) || isLMS(prev + d))) {
                break;
            }
        if (diff) {
            name++;
            prev = pos;
        }
        pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2;
        SA[n1 + pos] = name - 1;
    }
    for (int i = n - 1, j = n - 1; i >= n1; i--) if (SA[i] >= 0) {
        SA[j--] = SA[i];
    }
    int *SA1 = SA, *s1 = SA + n - n1;
    if (name < n1) {
        buildSA((unsigned char*) s1, SA1, n1, name - 1, sizeof(int));
    }
    else {
        for (int i = 0; i < n1; i++) {
            SA1[s1[i]] = i;
        }
    }
    bkt = (int*) malloc(sizeof(int) * (K + 1));
    getBuckets(s, bkt, n, K, cs, 1);
    for (int i = 1, j = 0; i < n; i++) if (isLMS(i)) {
        s1[j++] = i;
    }
    for (int i = 0; i < n1; i++) {
        SA1[i] = s1[SA1[i]];
    }
    for (int i = n1; i < n; i++) {
        SA[i] = -1;
    }
    for (int i = n1 - 1; i >= 0; i--) {
        int j = SA[i];
        SA[i] = -1;
        SA[--bkt[chr(j)]] = j;
    }
    induceSAl(t, SA, s, bkt, n, K, cs, 0);
    induceSAs(t, SA, s, bkt, n, K, cs, 1);
    free(bkt);
    free(t);
}
struct SuffixArray {
    static const int MAXN = 3e5 + 5;
    static const int MAXC = 256;
    static const unsigned char SEP = '$';
    int SA[MAXN], RA[MAXN];
    int Phi[MAXN], PLCP[MAXN];
    int LCP[MAXN];
    int n;
    unsigned char s[MAXN];

    void build(char* t) {
        n = strlen(t);
        for (int i = 0; i < n; i++) {
            s[i] = t[i];
            RA[i] = SA[i] = 0;
            Phi[i] = PLCP[i] = LCP[i] = 0;
        }
        s[n] = 0;
        buildSA(s, SA, n, MAXC, 1);
        for (int i = 0; i < n; i++) {
            RA[SA[i]] = i;
        }
        buildLCP();
    }
    void buildLCP() {
        int L = 0;
        Phi[SA[0]] = -1;
        for (int i = 1; i < n; i++) Phi[SA[i]] = SA[i - 1];
        for (int i = 0; i < n; i++) {
            if (!~Phi[i]) {PLCP[i] = 0; continue;}
            while (s[i + L] == s[Phi[i] + L] && s[i + L] != SEP) L++;
            PLCP[i] = L;
            L = max(L - 1, 0);
        }
        for (int i = 0; i < n; i++) LCP[i] = PLCP[SA[i]];
    }
} sa;

template<class T, class cmp = less<T> > struct RMQ {
    int n;
    vector<T> a;
    vector<vector<T> > f;

    T best(T a, T b) {
        if (cmp()(a, b)) return a;
        return b;
    }
    void init(int n) {
        this->n = n;
        int p = 1; while ((1 << p) < n) p++;
        a.resize(n), f.resize(p + 1);
        for (int i = 0; i < (int) f.size(); i++) {
            f[i].resize(n);
        }
    }
    void upd(int u, T x) {
        a[u] = x;
    }
    void build() {
        for (int i = 0; i < n; i++) f[0][i] = a[i];
        for (int l = 0, k; (k = 1 << l) < n; l++) {
            for (int i = 0; i + k < n; i++) {
                f[l + 1][i] = best(f[l][i], f[l][i + k]);
            }
        }
    }
    T query(int a, int b) {
        int l = a == b ? 0 : __lg(b - a);
        return best(f[l][a], f[l][b - (1 << l) + 1]);
    }
};
RMQ<int> rmq;

const int maxn = 1e5 + 5;
string s, ss;
int n;
int k[maxn];
string t[maxn];
int pos[maxn];

int findprv(int t, int len) {
    int lo = 0, hi = t;
    while (lo < hi) {
        int mi = lo + hi >> 1;
        if (rmq.query(mi + 1, t) < len) {
            lo = mi + 1;
        }
        else {
            hi = mi;
        }
    }
    return lo + hi >> 1;
}
int findnxt(int t, int len) {
    int lo = t, hi = sz(ss) - 1;
    while (lo < hi) {
        int mi = lo + hi + 1 >> 1;
        if (rmq.query(t + 1, mi) >= len) {
            lo = mi;
        }
        else {
            hi = mi - 1;
        }
    }
    return lo + hi >> 1;
}

void chemthan() {
    cin >> s >> n;
    ss = s + "$";
    FOR(i, 0, n) {
        cin >> k[i] >> t[i];
        pos[i] = sz(ss);
        ss += t[i] + "$";
    }
    sa.build((char *) ss.data());
    rmq.init(sz(ss));
    FOR(i, 0, sz(ss)) {
        rmq.upd(i, sa.LCP[i]);
    }
    rmq.build();
    int cnt = 0;
    FOR(i, 0, n) {
        int x = pos[i];
        x = sa.RA[x];
        int lo = findprv(x, sz(t[i]));
        int hi = findnxt(x, sz(t[i]));
        static int vals[maxn];
        int num = 0;
        FOR(j, lo, hi + 1) {
            int p = sa.SA[j];
            if (p < sz(s)) {
                vals[num++] = p;
            }
            cnt++;
        }
        assert(cnt <= 2000000);
        if (num < k[i]) {
            cout << -1 << "\n";
            continue;
        }
        sort(vals, vals + num);
        int res = INF;
        FOR(j, 0, num - k[i] + 1) {
            chkmin(res, vals[j + k[i] - 1] - vals[j] + sz(t[i]));
        }
        cout << res << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const long long MAXN = 100005;
const long long mod = 1e9+9;
string s;
pair<long long,long long> que[MAXN];
vector<pair<long long,long long> > pos[MAXN];
vector<long long> occ[MAXN];
long long pw[MAXN],H[MAXN];
long long ans[MAXN];
void fill_hash(string &s,long long hash[MAXN],long long MOD){
    hash[0] = s[0];
    for(long long i = 1; i < s.size(); i++){ hash[i] = (hash[i-1] * 256 + s[i]) % MOD;}
}
long long get_range(long long p,long long len,long long hash[MAXN],long long MOD){
    if(p == 0) return hash[len-1];
    long long R = hash[p + len - 1];
    long long L = (hash[p - 1] * pw[len]) % MOD;
    return (R - L + MOD) % MOD;
}
long long getHash(string &s){
    long long res = 0;
    for(long long i = 0; i < s.size(); i++) res = (res * 256 + s[i]) % mod;
    return (long long)res;
}
string cand[100005];
int main(){
    memset(ans,-1,sizeof(ans));
    cin >> s;
    long long q; cin >> q;
    pw[0] = 1;
    for(long long i = 1; i < MAXN; i++) pw[i] = (pw[i-1] * 256) % mod;
    for(long long i = 1; i <= q; i++){
        cin >> que[i].second >> cand[i];
        que[i].first = getHash(cand[i]);
        pos[cand[i].size()].push_back(make_pair(que[i].first,i));
    }
    fill_hash(s,H,mod);
    for(long long i = 1; i <= s.size(); i++){
        if(pos[i].size() == 0) continue;
        sort(pos[i].begin(),pos[i].end());
        for(long long j = 0; j < s.size(); j++){
            if(j + i > s.size()) break;
            long long hat = get_range(j,i,H,mod);
            auto it = lower_bound(pos[i].begin(),pos[i].end(),make_pair(hat,(long long)-1));
            if(it == pos[i].end()) continue;
            if(it->first == hat){
                occ[it->second].push_back(j);
            }
        }
    }
    for(long long i = 1; i <= q; i++){
        if(occ[i].size() < que[i].second) continue;
        for(long long j = 0; j + que[i].second <= occ[i].size(); j++){
            long long l = occ[i][j];
            long long r = occ[i][j+que[i].second - 1];
            if(ans[i] == -1) ans[i] = r - l + cand[i].size();
            else ans[i] = min(ans[i],r - l + (long long)cand[i].size());
        }
    }
    for(long long i = 1; i <= q; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 100005;
const int mod = 1e9+223;
string s;
pair<int,int> que[MAXN];
vector<pair<int,int> > pos[MAXN];
vector<int> occ[MAXN];
long long pw[MAXN],H[MAXN];
int ans[MAXN];
void fill_hash(string &s,long long hash[MAXN],long long MOD){
    hash[0] = s[0];
    for(int i = 1; i < s.size(); i++){ hash[i] = (hash[i-1] * 256 + s[i]) % MOD;}
}
int get_range(int p,int len,long long hash[MAXN],long long MOD){
    if(p == 0) return hash[len-1];
    int R = hash[p + len - 1];
    int L = (hash[p - 1] * pw[len]) % MOD;
    return (R - L + MOD) % MOD;
}
int getHash(string &s){
    long long res = 0;
    for(int i = 0; i < s.size(); i++) res = (res * 256 + s[i]) % mod;
    return (int)res;
}
string cand[100005];
int main(){
    memset(ans,-1,sizeof(ans));
    cin >> s;
    int q; cin >> q;
    pw[0] = 1;
    for(int i = 1; i < MAXN; i++) pw[i] = (pw[i-1] * 256) % mod;
    for(int i = 1; i <= q; i++){
        cin >> que[i].second >> cand[i];
        que[i].first = getHash(cand[i]);
        pos[cand[i].size()].push_back(make_pair(que[i].first,i));
    }
    fill_hash(s,H,mod);
    for(int i = 1; i <= s.size(); i++){
        if(pos[i].size() == 0) continue;
        sort(pos[i].begin(),pos[i].end());
        for(int j = 0; j < s.size(); j++){
            if(j + i > s.size()) break;
            int hat = get_range(j,i,H,mod);
            auto it = lower_bound(pos[i].begin(),pos[i].end(),make_pair(hat,-1));
            if(it == pos[i].end()) continue;
            occ[it->second].push_back(j);
        }
    }
    for(int i = 1; i <= q; i++){
        if(occ[i].size() < que[i].second) continue;
        for(int j = 0; j + que[i].second <= occ[i].size(); j++){
            int l = occ[i][j];
            int r = occ[i][j+que[i].second - 1];
            if(ans[i] == -1) ans[i] = r - l + cand[i].size();
            else ans[i] = min(ans[i],r - l + (int)cand[i].size());
        }
    }
    for(int i = 1; i <= q; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 100005;
const int mod = 1e9+223;
string s;
pair<int,int> que[MAXN];
vector<pair<int,int> > pos[MAXN];
vector<int> occ[MAXN];
long long pw[MAXN],H[MAXN];
int ans[MAXN];
void fill_hash(string &s,long long hash[MAXN],long long MOD){
    hash[0] = s[0];
    for(int i = 1; i < s.size(); i++){ hash[i] = (hash[i-1] * 256 + s[i]) % MOD;}
}
int get_range(int p,int len,long long hash[MAXN],long long MOD){
    if(p == 0) return hash[len-1];
    int R = hash[p + len - 1];
    int L = (hash[p - 1] * pw[len]) % MOD;
    return (R - L + MOD) % MOD;
}
int getHash(string &s){
    long long res = 0;
    for(int i = 0; i < s.size(); i++) res = (res * 256 + s[i]) % mod;
    return (int)res;
}
string cand[100005];
int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    memset(ans,-1,sizeof(ans));
    cin >> s;
    int q; cin >> q;
    pw[0] = 1;
    for(int i = 1; i < MAXN; i++) pw[i] = (pw[i-1] * 256) % mod;
    for(int i = 1; i <= q; i++){
        cin >> que[i].second >> cand[i];
        que[i].first = getHash(cand[i]);
        pos[cand[i].size()].push_back(make_pair(que[i].first,i));
    }
    fill_hash(s,H,mod);
    for(int i = 1; i <= s.size(); i++){
        if(pos[i].size() == 0) continue;
        sort(pos[i].begin(),pos[i].end());
        for(int j = 0; j < s.size(); j++){
            if(j + i > s.size()) break;
            int hat = get_range(j,i,H,mod);
            auto it = lower_bound(pos[i].begin(),pos[i].end(),make_pair(hat,-1));
            if(it == pos[i].end()) continue;
            if(it->first == hat){
                occ[it->second].push_back(j);
            }
        }
    }
    for(int i = 1; i <= q; i++){
        if(occ[i].size() < que[i].second) continue;
        for(int j = 0; j + que[i].second <= occ[i].size(); j++){
            int l = occ[i][j];
            int r = occ[i][j+que[i].second - 1];
            if(ans[i] == -1) ans[i] = r - l + cand[i].size();
            else ans[i] = min(ans[i],r - l + (int)cand[i].size());
        }
    }
    for(int i = 1; i <= q; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const long long MAXN = 100005;
const long long mod = 1e9+9;
string s;
pair<long long,long long> que[MAXN];
vector<pair<long long,long long> > pos[MAXN];
vector<long long> occ[MAXN];
long long pw[MAXN],H[MAXN];
long long ans[MAXN];
void fill_hash(string &s,long long hash[MAXN],long long MOD){
    hash[0] = s[0];
    for(long long i = 1; i < s.size(); i++){ hash[i] = (hash[i-1] * 256 + s[i]) % MOD;}
}
long long get_range(long long p,long long len,long long hash[MAXN],long long MOD){
    if(p == 0) return hash[len-1];
    long long R = hash[p + len - 1];
    long long L = (hash[p - 1] * pw[len]) % MOD;
    return (R - L + MOD) % MOD;
}
long long getHash(string &s){
    long long res = 0;
    for(long long i = 0; i < s.size(); i++) res = (res * 256 + s[i]) % mod;
    return (long long)res;
}
string cand[100005];
int main(){
    memset(ans,-1,sizeof(ans));
    cin >> s;
    long long q; cin >> q;
    pw[0] = 1;
    for(long long i = 1; i < MAXN; i++) pw[i] = (pw[i-1] * 256) % mod;
    for(long long i = 1; i <= q; i++){
        cin >> que[i].second >> cand[i];
        que[i].first = getHash(cand[i]);
        pos[cand[i].size()].push_back(make_pair(que[i].first,i));
    }
    fill_hash(s,H,mod);
    for(long long i = 1; i <= s.size(); i++){
        if(pos[i].size() == 0) continue;
        sort(pos[i].begin(),pos[i].end());
        for(long long j = 0; j < s.size(); j++){
            if(j + i > s.size()) break;
            long long hat = get_range(j,i,H,mod);
            auto it = lower_bound(pos[i].begin(),pos[i].end(),make_pair(hat,-1));
            if(it == pos[i].end()) continue;
            occ[it->second].push_back(j);
        }
    }
    for(long long i = 1; i <= q; i++){
        if(occ[i].size() < que[i].second) continue;
        for(long long j = 0; j + que[i].second <= occ[i].size(); j++){
            long long l = occ[i][j];
            long long r = occ[i][j+que[i].second - 1];
            if(ans[i] == -1) ans[i] = r - l + cand[i].size();
            else ans[i] = min(ans[i],r - l + (long long)cand[i].size());
        }
    }
    for(long long i = 1; i <= q; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = (int)1e5 + 1, seed = 27, mod1 = (int)1e9 + 7;
int n, q, len[maxn], rep[maxn], ord[maxn], ans[maxn];
char buf[maxn], pat[maxn];
LL pw[maxn], h[maxn], val[maxn];
unordered_map<LL, vector<int> > Hash;
int main() {
	scanf("%s%d", buf, &q);
	n = strlen(buf);
	pw[0] = 1;
	for(int i = 0; i < n; ++i) {
		int ch = buf[i] - 'a' + 1;
		LL h1 = h[i];
		h1 = (h1 * seed + ch) % mod1;
		h[i + 1] = h1;
		LL p1 = pw[i];
		p1 = p1 * seed % mod1;
		pw[i + 1] = p1;
	}
	for(int i = 0; i < q; ++i) {
		scanf("%d%s", rep + i, pat);
		len[i] = strlen(pat);
		LL h1 = 0;
		for(int j = 0; j < len[i]; ++j) {
			int ch = pat[j] - 'a' + 1;
			h1 = (h1 * seed + ch) % mod1;
		}
		val[i] = h1;
		ord[i] = i;
	}
	sort(ord, ord + q, [&](int const &u, int const &v) {
		return len[u] < len[v];
	});
	for(int o = 0, stp = 0; o < q; ++o) {
		int i = ord[o];
		int &res = ans[i] = maxn;
		if(stp != len[i]) {
			stp = len[i];
			unordered_map<LL, vector<int> >(n - stp + 1).swap(Hash);
			LL p1 = mod1 - pw[stp];
			for(int j = 0, k = j + stp; k <= n; ++j, ++k) {
				LL h1 = h[j];
				LL h2 = h[k];
				h1 = (h1 * p1 + h2) % mod1;
				Hash[h1].push_back(j);
			}
		}
		unordered_map<LL, vector<int> >::const_iterator it = Hash.find(val[i]);
		if(it != Hash.end()) {
			vector<int> const &seq = it -> second;
			int sz = seq.size();
			for(int j = 0, k = rep[i] - 1; k < sz; ++j, ++k)
				res = min(res, seq[k] - seq[j] + len[i]);
		}
	}
	for(int i = 0; i < q; ++i)
		printf("%d\n", ans[i] < maxn ? ans[i] : -1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = (int)1e5 + 1, seed = 27, mod1 = (int)1e9 + 7, mod2 = (int)1e9 + 9;
int n, q, len[maxn], rep[maxn], ord[maxn], ans[maxn];
char buf[maxn], pat[maxn];
LL pw[maxn], h[maxn], val[maxn];
unordered_map<LL, vector<int> > Hash;
int main() {
	scanf("%s%d", buf, &q);
	n = strlen(buf);
	pw[0] = 1LL << 30 | 1;
	for(int i = 0; i < n; ++i) {
		int ch = buf[i] - 'a' + 1;
		LL h1 = h[i] >> 30, h2 = h[i] & ((1 << 30) - 1);
		h1 = (h1 * seed + ch) % mod1;
		h2 = (h2 * seed + ch) % mod2;
		h[i + 1] = h1 << 30 | h2;
		LL p1 = pw[i] >> 30, p2 = pw[i] & ((1 << 30) - 1);
		p1 = p1 * seed % mod1;
		p2 = p2 * seed % mod2;
		pw[i + 1] = p1 << 30 | p2;
	}
	for(int i = 0; i < q; ++i) {
		scanf("%d%s", rep + i, pat);
		len[i] = strlen(pat);
		LL h1 = 0, h2 = 0;
		for(int j = 0; j < len[i]; ++j) {
			int ch = pat[j] - 'a' + 1;
			h1 = (h1 * seed + ch) % mod1;
			h2 = (h2 * seed + ch) % mod2;
		}
		val[i] = h1 << 30 | h2;
		ord[i] = i;
	}
	sort(ord, ord + q, [&](int const &u, int const &v) {
		return len[u] < len[v];
	});
	for(int o = 0, stp = 0; o < q; ++o) {
		int i = ord[o];
		int &res = ans[i] = maxn;
		if(stp != len[i]) {
			stp = len[i];
			unordered_map<LL, vector<int> >(n - stp + 1).swap(Hash);
			LL p1 = mod1 - (pw[stp] >> 30), p2 = mod2 - (pw[stp] & ((1 << 30) - 1));
			for(int j = 0, k = j + stp; k <= n; ++j, ++k) {
				LL h1 = h[j] >> 30, h2 = h[j] & ((1 << 30) - 1);
				LL h3 = h[k] >> 30, h4 = h[k] & ((1 << 30) - 1);
				h1 = (h1 * p1 + h3) % mod1;
				h2 = (h2 * p2 + h4) % mod2;
				Hash[h1 << 30 | h2].push_back(j);
			}
		}
		unordered_map<LL, vector<int> >::const_iterator it = Hash.find(val[i]);
		if(it != Hash.end()) {
			vector<int> const &seq = it -> second;
			int sz = seq.size();
			for(int j = 0, k = rep[i] - 1; k < sz; ++j, ++k)
				res = min(res, seq[k] - seq[j] + len[i]);
		}
	}
	for(int i = 0; i < q; ++i)
		printf("%d\n", ans[i] < maxn ? ans[i] : -1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = (int)1e5 + 1, seed = 27, mod1 = (int)1e9 + 7;
int n, q, len[maxn], rep[maxn], ord[maxn], ans[maxn];
char buf[maxn], pat[maxn];
LL pw[maxn], h[maxn], val[maxn];
unordered_map<LL, vector<int> > Hash;
int main() {
	scanf("%s%d", buf, &q);
	n = strlen(buf);
	pw[0] = 1;
	for(int i = 0; i < n; ++i) {
		int ch = buf[i] - 'a' + 1;
		LL h1 = h[i];
		h1 = (h1 * seed + ch) % mod1;
		h[i + 1] = h1;
		LL p1 = pw[i];
		p1 = p1 * seed % mod1;
		pw[i + 1] = p1;
	}
	for(int i = 0; i < q; ++i) {
		scanf("%d%s", rep + i, pat);
		len[i] = strlen(pat);
		LL h1 = 0;
		for(int j = 0; j < len[i]; ++j) {
			int ch = pat[j] - 'a' + 1;
			h1 = (h1 * seed + ch) % mod1;
		}
		val[i] = h1;
		ord[i] = i;
	}
	sort(ord, ord + q, [&](int const &u, int const &v) {
		return len[u] < len[v];
	});
	for(int o = 0, stp = 0; o < q; ++o) {
		int i = ord[o];
		int &res = ans[i] = maxn;
		if(stp != len[i]) {
			stp = len[i];
			unordered_map<LL, vector<int> >().swap(Hash);
			for(int p = o; p < q && len[ord[p]] == stp; ++p)
				Hash[val[ord[p]]] = vector<int>();
			LL p1 = mod1 - pw[stp];
			for(int j = 0, k = j + stp; k <= n; ++j, ++k) {
				LL h1 = h[j];
				LL h2 = h[k];
				h1 = (h1 * p1 + h2) % mod1;
				unordered_map<LL, vector<int> >::iterator it = Hash.find(h1);
				if(it != Hash.end())
					(it -> second).push_back(j);
			}
		}
		vector<int> const &seq = Hash[val[i]];
		int sz = seq.size();
		for(int j = 0, k = rep[i] - 1; k < sz; ++j, ++k)
			res = min(res, seq[k] - seq[j] + len[i]);
	}
	for(int i = 0; i < q; ++i)
		printf("%d\n", ans[i] < maxn ? ans[i] : -1);
	return 0;
}