#include <bits/stdc++.h>
using namespace std;
int ch[100005][26], ed[100005], fail[100005], output[100005];
int rt = 1, tot = 1;
void insert(string &T, int id) {
  int t = T.length();
  int n = rt;
  for (int i = (0); i <= (t - 1); i += (1)) {
    int x = T[i] - 'a';
    if (!ch[n][x]) ch[n][x] = ++tot;
    n = ch[n][x];
  }
  ed[n] = id;
}
queue<int> bfs;
void Aho_Corasick() {
  bfs.push(rt);
  for (int i = (0); i <= (25); i += (1)) {
    if (ch[rt][i]) fail[ch[rt][i]] = rt;
  }
  while (!bfs.empty()) {
    int u = bfs.front();
    bfs.pop();
    for (int i = (0); i <= (25); i += (1)) {
      int v = ch[u][i];
      if (!v) continue;
      int f = fail[u];
      while (f && !ch[f][i]) f = fail[f];
      if (!f)
        f = rt;
      else
        f = ch[f][i];
      fail[v] = f;
      if (ed[f])
        output[v] = f;
      else
        output[v] = output[f];
      bfs.push(v);
    }
  }
}
int occ[100005], len[100005];
queue<int> pos[100005];
int ans[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  int n;
  cin >> S >> n;
  int s = S.length();
  for (int i = (1); i <= (n); i += (1)) {
    string T;
    int k;
    cin >> k >> T;
    occ[i] = k;
    len[i] = T.length();
    insert(T, i);
  }
  Aho_Corasick();
  for (int i = (1); i <= (n); i += (1)) ans[i] = 1000000000;
  int j = 1;
  for (int i = (0); i <= (s - 1); i += (1)) {
    int x = S[i] - 'a';
    while (j && !ch[j][x]) j = fail[j];
    if (!j)
      j = rt;
    else
      j = ch[j][x];
    int tj = j;
    while (tj) {
      if (ed[tj]) {
        int id = ed[tj];
        pos[id].push(i);
        while (pos[id].size() > occ[id]) pos[id].pop();
        if (pos[id].size() == occ[id]) {
          ans[id] = min(ans[id], i - pos[id].front() + len[id]);
        }
      }
      tj = output[tj];
    }
  }
  for (int i = (1); i <= (n); i += (1)) {
    printf("%d\n", (ans[i] == 1000000000) ? -1 : ans[i]);
  }
  return 0;
}
