#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define forn(i,n) for(int i=0;i<n;i++)
#define minf numeric_limits<int>::min()
#define inf numeric_limits<int>::max()
#define linf numeric_limits<long>::max()
#define lminf numeric_limits<long>::min()
#define llinf numeric_limits<long long>::max()
#define llminf numeric_limits<long long>::min()
#define forln(i,n) for(long i=0;i<n;i++)
#define forlln(i,n) for(long long i=0;i<n;i++)
#define For(i,s,e) for(int i=s; i<=e; i++)
#define rFor(i,s,e) for(int i=s; i>=e; i--)
#define ll long long
#define l long
#define ivec vector<int>
#define lvec vector<l>
#define llvec vector<ll>
#define iimap map<int, int>
#define llmap map<ll, ll>
#define illmap map<int, ll>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ipair pair<int,int>
#define lpair pair<l,l>
#define llpair pair<ll,ll>
#define vec vector
#define CASE int test; cin>>test; forn(_,test)
#define len(a) a.size()
#define all(a) a.begin(), a.end()

using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

template<typename T> istream & operator>>(istream& in, vec<T> &a){
    forn(i,a.size()) in>>a[i];
    return in;
}
template<typename T> ostream & operator<<(ostream& out, vec<T> &a){
    forn(i,a.size()) out<<a[i]<<" ";
    out<<endl;
    return out;
}
template<typename T> T max(vec<T> a){
    T ans=numeric_limits<T>::min();
    forn(i, a.size()) ans=max(ans, a[i]);
    return ans;
}
template<typename T> T min(vec<T> a){
    T ans=numeric_limits<T>::max();
    forn(i, a.size()) ans=min(ans, a[i]);
    return ans;
}

const int K = 26;
int sz=0;
struct Vertex {
    int next[K];
    int leaf = -1;
    int p = -1;
    char pch;
    int link = -1;
    int go[K];
    int dicsuff=-1;
    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    t[v].leaf = sz++;
}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);
    }
    return t[v].link;
}

int go(int v, char ch) {
    int c = ch - 'a';
    if (t[v].go[c] == -1) {
        if (t[v].next[c] != -1)
            t[v].go[c] = t[v].next[c];
        else
            t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
}
int godict(int v){
    if(t[v].dicsuff==-1){
        int u=get_link(v);
        if(u!=0 && t[u].leaf!=-1) t[v].dicsuff=u;
        else t[v].dicsuff = v==0 ? 0 : godict(u);
    }
    return t[v].dicsuff;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    t[0].dicsuff=-1;
    string s;
    cin>>s;
    int n=len(s);
    ivec ki;
    ivec st;
    CASE{
        int k; string m;
        cin>>k>>m;
        add_string(m);
        ki.pb(k);
        st.pb(len(m));
    }
    vec<ivec> ind(test);
    int v=0;
    forn(i,n){
        v=go(v,s[i]);
        if(t[v].leaf!=-1) ind[t[v].leaf].pb(i);
        int u=godict(v);
        while(u!=0){
            ind[t[u].leaf].pb(i);
            u=godict(u);
        }
    }
    forn(i,test){
        if(ind[i].size()<ki[i]) cout<<-1<<endl;
        else{
            int k=ki[i];
            int len=inf;
            For(j,0,len(ind[i])-k){
                len=min(len,ind[i][j+k-1]-ind[i][j]+st[i]);
            }
            cout<<len<<endl;
        }
    }

}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;

struct Vertex {
    int next[K];
    bool leaf = false;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

map <string, int> m;
map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    m[s] = v;
    m2[v] = s;
    t[v].leaf = true;
    // printf("%s\n", );
    // cout << s << endl;
    // cout << v << endl;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);

    }

    return t[v].link;
}
int getExit(int v)
{
    int u = t[v].link;
    while(u!= 0)
    {
        if (t[u].leaf)
        {
            t[v].exit = u;
            break;
        }
        u = t[u].link;
    }
}
int go(int v, char ch) {
    int c = ch - 'a';
    if (c < 0)
        c = ch - 'A';
    if (t[v].go[c] == -1) {
        if (t[v].next[c] != -1)
            t[v].go[c] = t[v].next[c];
        else
            t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
}

// set <string> visitados;
map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        // cout << s[i] << " " << v << endl;
        int u = s[i]-'a';
        if (u < 0)
            u = s[i] - 'A';
        // se o nó em que estou tem filho s[i]
        if (t[v].next[u]!= -1)
        {
            v = t[v].next[u];
            // cout << v << endl;
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
            }
            int v2 = t[v].exit;
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 = t[v2].exit;
            }
        }
        else
        {
            while (t[v].next[u]== -1 && v!=0)
            {
                v = t[v].link;
                // cout << v << endl;
                // printf("1\n");
            }
            if (t[v].next[u] != -1)
                v = t[v].next[u];
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
                // v = t[v].exit;
            }
            int v2 = t[v].exit;
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 = t[v2].exit;
            }

        }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    // map <string, int>
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
        contaEntrada[s]=mp(sz,i);
    }
    for (int v = 0; v < t.size(); ++v)
    {
        get_link(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }
    for (int v = 0; v < t.size(); ++v)
    {
        getExit(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        // printf("%s\n", );
        // cout << entrada[i].fi << endl;
        // cout << posicoesOcorrencias[i].size() << endl;
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            // printf("%d\n",-1 );
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
        // for (int j = 0; j < posicoesOcorrencias[i].size(); ++j)
        // {
        //     printf("%d ",posicoesOcorrencias[i][j] );
        // }
        // printf("\n");
    }
    // for (int i = 0; i < entrada.size(); ++i)
    // {
    //     cout << entrada[i]<<endl;
    //     if (visitados.count(entrada[i]))
    //         cout << 'y'<<endl;
    //     else
    //         cout << 'n'<<endl;
    // }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;

struct Vertex {
    int next[K];
    bool leaf = false;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

map <string, int> m;
map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    m[s] = v;
    m2[v] = s;
    t[v].leaf = true;
    // printf("%s\n", );
    // cout << s << endl;
    // cout << v << endl;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);

    }

    return t[v].link;
}
// int getExit(int v)
// {
//     int u = t[v].link;
//     while(u!= 0)
//     {
//         if (t[u].leaf)
//         {
//             t[v].exit = u;
//             break;
//         }
//         u = t[u].link;
//     }
// }
int go(int v, char ch) {
    int c = ch - 'a';
    if (c < 0)
        c = ch - 'A';
    if (t[v].go[c] == -1) {
        if (t[v].next[c] != -1)
            t[v].go[c] = t[v].next[c];
        else
            t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
}

int getExit(int v){
    // cout << v << endl;
    if (v == 0 || t[v].p == 0)
        return -1;
    if(t[v].exit==-1){
        int u=get_link(v);
        if(u!=-1 && t[u].leaf) t[v].exit=u;
        else t[v].exit = v==0 ? 0 : getExit(u);
    }
    return t[v].exit;
}
// set <string> visitados;
map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        // cout << s[i] << " " << v << endl;
        int u = s[i]-'a';
        if (u < 0)
            u = s[i] - 'A';
        // se o nó em que estou tem filho s[i]
        if (t[v].next[u]!= -1)
        {
            v = t[v].next[u];
            // cout << v << endl;
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }
        }
        else
        {
            while (t[v].next[u]== -1 && v!=0)
            {
                v = t[v].link;
                // cout << v << endl;
                // printf("1\n");
            }
            if (t[v].next[u] != -1)
                v = t[v].next[u];
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
                // v = t[v].exit;
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }

        }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    // map <string, int>
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
        contaEntrada[s]=mp(sz,i);
    }
    for (int v = 0; v < t.size(); ++v)
    {
        get_link(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }
    // for (int v = 0; v < t.size(); ++v)
    // {
    //     getExit(v);
    //     // printf("%d ",v );
    //     // printf("%c ",t[v].pch );
    //     // printf("%d ",t[v].exit );
    //     // printf("\n");
    // }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        // printf("%s\n", );
        // cout << entrada[i].fi << endl;
        // cout << posicoesOcorrencias[i].size() << endl;
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            // printf("%d\n",-1 );
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
        // for (int j = 0; j < posicoesOcorrencias[i].size(); ++j)
        // {
        //     printf("%d ",posicoesOcorrencias[i][j] );
        // }
        // printf("\n");
    }
    // for (int i = 0; i < entrada.size(); ++i)
    // {
    //     cout << entrada[i]<<endl;
    //     if (visitados.count(entrada[i]))
    //         cout << 'y'<<endl;
    //     else
    //         cout << 'n'<<endl;
    // }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;

struct Vertex {
    int next[K];
    bool leaf = false;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

map <string, int> m;
map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    m[s] = v;
    m2[v] = s;
    t[v].leaf = true;
    // printf("%s\n", );
    // cout << s << endl;
    // cout << v << endl;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);

    }

    return t[v].link;
}
// int getExit(int v)
// {
//     if (t[v].exit != -1)
//         return t[v].exit;
//     int u = t[v].link;
//     while(u!= 0)
//     {
//         if (t[u].leaf)
//         {
//             t[v].exit = u;
//             break;
//         }
//         u = t[u].link;
//     }
//     return t[v].exit = u;
// }
int go(int v, char ch) {
    int c = ch - 'a';
    if (t[v].go[c] == -1) {
        if (t[v].next[c] != -1)
            t[v].go[c] = t[v].next[c];
        else
            t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
}

int getExit(int v){
    // cout << v << endl;
    if (v == 0 || t[v].p == 0)
        return -1;
    if(t[v].exit==-1){
        int u=get_link(v);
        if(u!=-1 && t[u].leaf) t[v].exit=u;
        else t[v].exit = v==0 ? 0 : getExit(u);
    }
    return t[v].exit;
}
// set <string> visitados;
map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        // cout << s[i] << " " << v << endl;
        // int u = s[i]-'a';
        // if (u < 0)
        //     u = s[i] - 'A';
        v = go(v, s[i]);
        if (t[v].leaf )
        {
            visitados[m2[v]]=1;
            posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
        }

        int v2 =getExit(v);
        while (v2 != -1)
        {

            visitados[m2[v2]]=1;
            posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
            v2 =getExit(v2);
        }
        // se o nó em que estou tem filho s[i]
        // if (t[v].next[u]!= -1)
        // {
        //     v = t[v].next[u];
        //     // cout << v << endl;
        //     if (t[v].leaf)
        //     {
        //         visitados[m2[v]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
        //     }
        //     int v2 =getExit(v);
        //     while (v2 != -1)
        //     {

        //         visitados[m2[v2]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
        //         v2 =getExit(v2);
        //     }
        // }
        // else
        // {
        //     while (t[v].next[u]== -1 && v!=0)
        //     {

        //         // v = t[v].link;
        //         // cout << v << endl;
        //         // printf("1\n");
        //     }
        //     if (t[v].next[u] != -1)
        //         v = t[v].next[u];
        //     if (t[v].leaf)
        //     {
        //         visitados[m2[v]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
        //         // v = t[v].exit;
        //     }
        //     int v2 =getExit(v);
        //     while (v2 != -1)
        //     {

        //         visitados[m2[v2]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
        //         v2 =getExit(v2);
        //     }

        // }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    // map <string, int>
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
        contaEntrada[s]=mp(sz,i);
    }
    // for (int v = 0; v < t.size(); ++v)
    // {
    //     get_link(v);
    //     // printf("%d ",v );
    //     // printf("%c ",t[v].pch );
    //     // printf("%d ",t[v].exit );
    //     // printf("\n");
    // }
    // for (int v = 0; v < t.size(); ++v)
    // {
    //     getExit(v);
    //     // printf("%d ",v );
    //     // printf("%c ",t[v].pch );
    //     // printf("%d ",t[v].exit );
    //     // printf("\n");
    // }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        // printf("%s\n", );
        // cout << entrada[i].fi << endl;
        // cout << posicoesOcorrencias[i].size() << endl;
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            // printf("%d\n",-1 );
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
        // for (int j = 0; j < posicoesOcorrencias[i].size(); ++j)
        // {
        //     cout << m2[posicoesOcorrencias[i][j]] << " " ;
        //     // printf("%d ",posicoesOcorrencias[i][j] );
        // }
        // printf("\n");
    }
    // for (int i = 0; i < entrada.size(); ++i)
    // {
    //     cout << entrada[i]<<endl;
    //     if (visitados.count(entrada[i]))
    //         cout << 'y'<<endl;
    //     else
    //         cout << 'n'<<endl;
    // }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;

struct Vertex {
    int next[K];
    bool leaf = false;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

map <string, int> m;
map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    m[s] = v;
    m2[v] = s;
    t[v].leaf = true;
    // printf("%s\n", );
    // cout << s << endl;
    // cout << v << endl;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);
    }

    return t[v].link;
}
// int getExit(int v)
// {
//     if (t[v].exit != -1)
//         return t[v].exit;
//     int u = t[v].link;
//     while(u!= 0)
//     {
//         if (t[u].leaf)
//         {
//             t[v].exit = u;
//             break;
//         }
//         u = t[u].link;
//     }
//     return t[v].exit;
// }
int getExit(int v){
    // cout << v << endl;
    if (v == 0)
        return -1;
    if(t[v].exit==-1){
        int u=get_link(v);
        if(u!=-1 && t[u].leaf) t[v].exit=u;
        else t[v].exit = v==0 ? 0 : getExit(u);
    }
    return t[v].exit;
}

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

// set <string> visitados;
map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        // cout << s[i] << " " << v << endl;
        int u = s[i]-'a';
        if (u < 0)
            u = s[i] - 'A';
        // se o nó em que estou tem filho s[i]
        if (t[v].next[u]!= -1)
        {
            v = t[v].next[u];
            // cout << v << endl;
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }
        }
        else
        {
            while (t[v].next[u]== -1 && v!=0)
            {
                v = t[v].link;
                // cout << v << endl;
                // printf("1\n");
            }
            if (t[v].next[u] != -1)
                v = t[v].next[u];
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
                // v = t[v].exit;
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }

        }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    // map <string, int>
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
        contaEntrada[s]=mp(sz,i);
    }
    for (int v = 0; v < t.size(); ++v)
    {
        get_link(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }
    for (int v = 0; v < t.size(); ++v)
    {
        getExit(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        // printf("%s\n", );
        // cout << entrada[i].fi << endl;
        // cout << posicoesOcorrencias[i].size() << endl;
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            // printf("%d\n",-1 );
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
        // for (int j = 0; j < posicoesOcorrencias[i].size(); ++j)
        // {
        //     printf("%d ",posicoesOcorrencias[i][j] );
        // }
        // printf("\n");
    }
    // for (int i = 0; i < entrada.size(); ++i)
    // {
    //     cout << entrada[i]<<endl;
    //     if (visitados.count(entrada[i]))
    //         cout << 'y'<<endl;
    //     else
    //         cout << 'n'<<endl;
    // }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;
int sz=0;
struct Vertex {
    int next[K];
    int leaf = -1;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

// map <string, int> m;
// map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    t[v].leaf = sz++;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);

    }

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

int getExit(int v)
{
    if(t[v].exit==-1){
        int u=get_link(v);
        if(u!=0 && t[u].leaf!=-1) t[v].exit=u;
        else t[v].exit = v==0 ? 0 : getExit(u);
    }
    return t[v].exit;
}
// map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        v = go(v, s[i]);
        if (t[v].leaf != -1 )
        {
            posicoesOcorrencias[t[v].leaf].pb(i);
        }

        int v2 =getExit(v);
        while (v2 != 0 && v2 != -1)
        {
            posicoesOcorrencias[t[v2].leaf].pb(i);
            v2 =getExit(v2);
        }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    t[0].exit=-1;
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
    }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;

struct Vertex {
    int next[K];
    bool leaf = false;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

map <string, int> m;
map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    m[s] = v;
    m2[v] = s;
    t[v].leaf = true;
    // printf("%s\n", );
    // cout << s << endl;
    // cout << v << endl;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);

    }

    return t[v].link;
}
int getExit(int v)
{
    int u = t[v].link;
    while(u!= 0)
    {
        if (t[u].leaf)
        {
            t[v].exit = u;
            break;
        }
        u = t[u].link;
    }
    return t[v].exit;
}
int go(int v, char ch) {
    int c = ch - 'a';
    if (c < 0)
        c = ch - 'A';
    if (t[v].go[c] == -1) {
        if (t[v].next[c] != -1)
            t[v].go[c] = t[v].next[c];
        else
            t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
}

// set <string> visitados;
map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        // cout << s[i] << " " << v << endl;
        int u = s[i]-'a';
        if (u < 0)
            u = s[i] - 'A';
        // se o nó em que estou tem filho s[i]
        if (t[v].next[u]!= -1)
        {
            v = t[v].next[u];
            // cout << v << endl;
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }
        }
        else
        {
            while (t[v].next[u]== -1 && v!=0)
            {
                v = t[v].link;
                // cout << v << endl;
                // printf("1\n");
            }
            if (t[v].next[u] != -1)
                v = t[v].next[u];
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
                // v = t[v].exit;
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }

        }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    // map <string, int>
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
        contaEntrada[s]=mp(sz,i);
    }
    for (int v = 0; v < t.size(); ++v)
    {
        get_link(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }
    for (int v = 0; v < t.size(); ++v)
    {
        getExit(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        // printf("%s\n", );
        // cout << entrada[i].fi << endl;
        // cout << posicoesOcorrencias[i].size() << endl;
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            // printf("%d\n",-1 );
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
        // for (int j = 0; j < posicoesOcorrencias[i].size(); ++j)
        // {
        //     printf("%d ",posicoesOcorrencias[i][j] );
        // }
        // printf("\n");
    }
    // for (int i = 0; i < entrada.size(); ++i)
    // {
    //     cout << entrada[i]<<endl;
    //     if (visitados.count(entrada[i]))
    //         cout << 'y'<<endl;
    //     else
    //         cout << 'n'<<endl;
    // }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;
int sz=0;
struct Vertex {
    int next[K];
    int leaf = -1;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

map <string, int> m;
map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    m[s] = v;
    m2[v] = s;
    t[v].leaf = sz++;
    // printf("%s\n", );
    // cout << s << endl;
    // cout << v << endl;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);

    }

    return t[v].link;
}
// int getExit(int v)
// {
//     if (t[v].exit != -1)
//         return t[v].exit;
//     int u = t[v].link;
//     while(u!= 0)
//     {
//         if (t[u].leaf)
//         {
//             t[v].exit = u;
//             break;
//         }
//         u = t[u].link;
//     }
//     return t[v].exit = u;
// }
int go(int v, char ch) {
    int c = ch - 'a';
    if (t[v].go[c] == -1) {
        if (t[v].next[c] != -1)
            t[v].go[c] = t[v].next[c];
        else
            t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
}

int getExit(int v){
    // cout << v << endl;
    // if (v == 0 || t[v].p == 0)
    //     return -1;
    if(t[v].exit==-1){
        int u=get_link(v);
        if(u!=0 && t[u].leaf != -1) t[v].exit=u;
        else t[v].exit = v==0 ? 0 : getExit(u);
    }
    return t[v].exit;
}
// set <string> visitados;
map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        // cout << s[i] << " " << v << endl;
        // int u = s[i]-'a';
        // if (u < 0)
        //     u = s[i] - 'A';
        v = go(v, s[i]);
        if (t[v].leaf != -1 )
        {
            visitados[m2[v]]=1;
            posicoesOcorrencias[t[v].leaf].pb(i);
        }

        int v2 =getExit(v);
        while (v2 != 0 && v2 != -1)
        {

            visitados[m2[v2]]=1;
            posicoesOcorrencias[t[v2].leaf].pb(i);
            v2 =getExit(v2);
        }
        // se o nó em que estou tem filho s[i]
        // if (t[v].next[u]!= -1)
        // {
        //     v = t[v].next[u];
        //     // cout << v << endl;
        //     if (t[v].leaf)
        //     {
        //         visitados[m2[v]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
        //     }
        //     int v2 =getExit(v);
        //     while (v2 != -1)
        //     {

        //         visitados[m2[v2]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
        //         v2 =getExit(v2);
        //     }
        // }
        // else
        // {
        //     while (t[v].next[u]== -1 && v!=0)
        //     {

        //         // v = t[v].link;
        //         // cout << v << endl;
        //         // printf("1\n");
        //     }
        //     if (t[v].next[u] != -1)
        //         v = t[v].next[u];
        //     if (t[v].leaf)
        //     {
        //         visitados[m2[v]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
        //         // v = t[v].exit;
        //     }
        //     int v2 =getExit(v);
        //     while (v2 != -1)
        //     {

        //         visitados[m2[v2]]=1;
        //         posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
        //         v2 =getExit(v2);
        //     }

        // }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    t[0].exit=-1;
    // map <string, int>
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
        contaEntrada[s]=mp(sz,i);
    }
    // for (int v = 0; v < t.size(); ++v)
    // {
    //     get_link(v);
    //     // printf("%d ",v );
    //     // printf("%c ",t[v].pch );
    //     // printf("%d ",t[v].exit );
    //     // printf("\n");
    // }
    // for (int v = 0; v < t.size(); ++v)
    // {
    //     getExit(v);
    //     // printf("%d ",v );
    //     // printf("%c ",t[v].pch );
    //     // printf("%d ",t[v].exit );
    //     // printf("\n");
    // }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        // printf("%s\n", );
        // cout << entrada[i].fi << endl;
        // cout << posicoesOcorrencias[i].size() << endl;
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            // printf("%d\n",-1 );
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
        // for (int j = 0; j < posicoesOcorrencias[i].size(); ++j)
        // {
        //     cout << m2[posicoesOcorrencias[i][j]] << " " ;
        //     // printf("%d ",posicoesOcorrencias[i][j] );
        // }
        // printf("\n");
    }
    // for (int i = 0; i < entrada.size(); ++i)
    // {
    //     cout << entrada[i]<<endl;
    //     if (visitados.count(entrada[i]))
    //         cout << 'y'<<endl;
    //     else
    //         cout << 'n'<<endl;
    // }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define para(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define paraIni(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rpara(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define unicos(X) (X).erase(unique(all(X)),(X).end())
#define NL <<"\n"
#define EPS 1e-6
#define MOD 1000000007
#define iinf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int K = 26;

struct Vertex {
    int next[K];
    bool leaf = false;
    // ancesrtor
    int p = -1;
    // character of the ancestor
    char pch;
    // suffix link
    int link = -1;
    int exit = -1;
    int go[K];

    Vertex(int p=-1, char ch='$') : p(p), pch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

vector<Vertex> t(1);

map <string, int> m;
map <int, string> m2;
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (c < 0)
            c = ch - 'A';
        if (t[v].next[c] == -1) {
            t[v].next[c] = t.size();
            t.emplace_back(v, ch);
        }
        v = t[v].next[c];
    }
    m[s] = v;
    m2[v] = s;
    t[v].leaf = true;
    // printf("%s\n", );
    // cout << s << endl;
    // cout << v << endl;

}

int go(int v, char ch);

int get_link(int v) {
    if (t[v].link == -1) {
        if (v == 0 || t[v].p == 0)
            t[v].link = 0;
        else
            t[v].link = go(get_link(t[v].p), t[v].pch);

    }

    return t[v].link;
}
int getExit(int v)
{
    int u = t[v].link;
    while(u!= 0)
    {
        if (t[u].leaf)
        {
            t[v].exit = u;
            break;
        }
        u = t[u].link;
    }
}
int go(int v, char ch) {
    int c = ch - 'a';
    if (c < 0)
        c = ch - 'A';
    if (t[v].go[c] == -1) {
        if (t[v].next[c] != -1)
            t[v].go[c] = t[v].next[c];
        else
            t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
}

int getExit(int v){
    // cout << v << endl;
    if (v == 0 || t[v].p == 0)
        return -1;
    if(t[v].exit==-1){
        int u=get_link(v);
        if(u!=-1 && t[u].leaf) t[v].exit=u;
        else t[v].exit = v==0 ? 0 : getExit(u);
    }
    return t[v].exit;
}
// set <string> visitados;
map <string, int> visitados;
vector <pair<string, int>> entrada;
map <string, pair<int,int>> contaEntrada;
vector<int> posicoesOcorrencias[112345];
int percorreArvore(string s)
{
    int v = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        // cout << s[i] << " " << v << endl;
        int u = s[i]-'a';
        if (u < 0)
            u = s[i] - 'A';
        // se o nó em que estou tem filho s[i]
        if (t[v].next[u]!= -1)
        {
            v = t[v].next[u];
            // cout << v << endl;
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }
        }
        else
        {
            while (t[v].next[u]== -1 && v!=0)
            {
                v = t[v].link;
                // cout << v << endl;
                // printf("1\n");
            }
            if (t[v].next[u] != -1)
                v = t[v].next[u];
            if (t[v].leaf)
            {
                visitados[m2[v]]=1;
                posicoesOcorrencias[contaEntrada[m2[v]].se].pb(i);
                // v = t[v].exit;
            }
            int v2 =getExit(v);
            while (v2 != -1)
            {

                visitados[m2[v2]]=1;
                posicoesOcorrencias[contaEntrada[m2[v2]].se].pb(i);
                v2 =getExit(v2);
            }

        }

    }

}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    // map <string, int>
    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        string s;
        cin >> s;
        add_string(s);
        entrada.pb(mp(s,sz));
        contaEntrada[s]=mp(sz,i);
    }
    for (int v = 0; v < t.size(); ++v)
    {
        get_link(v);
        // printf("%d ",v );
        // printf("%c ",t[v].pch );
        // printf("%d ",t[v].exit );
        // printf("\n");
    }
    // for (int v = 0; v < t.size(); ++v)
    // {
    //     getExit(v);
    //     // printf("%d ",v );
    //     // printf("%c ",t[v].pch );
    //     // printf("%d ",t[v].exit );
    //     // printf("\n");
    // }

    percorreArvore(s);
    for (int i = 0; i < entrada.size(); ++i)
    {
        // printf("%s\n", );
        // cout << entrada[i].fi << endl;
        // cout << posicoesOcorrencias[i].size() << endl;
        if(posicoesOcorrencias[i].size() < entrada[i].se )
        {
            // printf("%d\n",-1 );
            cout << -1 << endl;
        }
        else
        {
            int tam = 0;
            int k = entrada[i].se-1;
            tam =posicoesOcorrencias[i][k] - posicoesOcorrencias[i][0];
            // printf("%d\n",tam );
            for (int j = 1; j+k < posicoesOcorrencias[i].size(); ++j)
            {
                if (posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j]  < tam)
                    tam = posicoesOcorrencias[i][j+k] - posicoesOcorrencias[i][j];
            }
            cout <<tam+ entrada[i].fi.size() << endl;
        }
        // for (int j = 0; j < posicoesOcorrencias[i].size(); ++j)
        // {
        //     printf("%d ",posicoesOcorrencias[i][j] );
        // }
        // printf("\n");
    }
    // for (int i = 0; i < entrada.size(); ++i)
    // {
    //     cout << entrada[i]<<endl;
    //     if (visitados.count(entrada[i]))
    //         cout << 'y'<<endl;
    //     else
    //         cout << 'n'<<endl;
    // }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 250;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 222;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 400;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 180;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 240;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

const int N = 100010;
char s[N], str[N];
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 500;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && str[i] != str[j]) j = nxt[j];
		nxt[++i] = ++j;
	}
}

int main()
{
	scanf("%s", s);
	int n = strlen(s);
    for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	int m;
	scanf("%d", &m);
	while (m--) {
		int t;
		scanf("%d%s", &t, str);
		int l = strlen(str);
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				printf("-1\n");
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				printf("-1\n");
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			printf("%d\n", ans);
		} else {
		    vector<int> pos;
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 550;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 300;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 400;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && str[i] != str[j]) j = nxt[j];
		nxt[++i] = ++j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

const int N = 100010;
char s[N], str[N];
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 333;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && str[i] != str[j]) j = nxt[j];
		nxt[++i] = ++j;
	}
}

int main()
{
	scanf("%s", s);
	int n = strlen(s);
    for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	int m;
	scanf("%d", &m);
	while (m--) {
		int t;
		scanf("%d%s", &t, str);
		int l = strlen(str);
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				printf("-1\n");
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				printf("-1\n");
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			printf("%d\n", ans);
		} else {
		    vector<int> pos;
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {100007, 10009};
const int mods[2] = {1000000009, 1000000007};
const int sz = 180;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1ULL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1ULL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				cout << -1 << endl;
				continue;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 350;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 450;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 500;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 350;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}