#include <bits/stdc++.h>
using std::queue;
using std::vector;
const int N = 1e5 + 5;
const int LEN = 350;
const int inf = 0x3f3f3f3f;
template <class T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
int son[26][N], n, m[N], idx = 1, fail[N], end[N], id, rans[N], kmp[N], len[N],
                         ANS[N], fa[N];
char s[N], t[N];
inline void insert(char *S, int LEN) {
  int ps = 1, nxt;
  for (int i = 1; i <= LEN; i++) {
    nxt = (S[i] - 'a');
    if (!son[nxt][ps]) son[nxt][ps] = (++idx);
    ps = son[nxt][ps];
  }
  end[id] = ps;
}
queue<int> Q;
vector<int> e[N];
vector<int> g[N];
inline void bfs() {
  for (int i = 0; i <= 25; i++)
    if (son[i][1])
      fail[son[i][1]] = 1, Q.push(son[i][1]);
    else
      son[i][1] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    e[fail[u]].emplace_back(u);
    for (int i = 0; i <= 25; i++) {
      if (son[i][u])
        fail[son[i][u]] = son[i][fail[u]], Q.push(son[i][u]);
      else
        son[i][u] = son[i][fail[u]];
    }
  }
}
inline void dfs(int x) {
  for (int v : e[x]) dfs(v), fa[v] = x;
}
inline void fz() {
  for (int i = 1; i <= len[id]; i++) kmp[i] = 0;
  kmp[1] = 0;
  int Ans = inf;
  for (int i = 2, j = 0; i <= len[id]; i++) {
    while (j && t[j + 1] != t[i]) j = kmp[j];
    if (t[j + 1] == t[i]) j++;
    kmp[i] = j;
  }
  int LEN = strlen(s + 1), cnt = 0;
  for (int i = 1, j = 0; i <= LEN; i++) {
    while (j && t[j + 1] != s[i]) j = kmp[j];
    if (t[j + 1] == s[i]) j++;
    if (j == len[id]) {
      ANS[++cnt] = i;
      j = kmp[j];
      if (cnt >= m[id]) Ans = std::min(Ans, ANS[cnt] - ANS[cnt - m[id] + 1]);
    }
  }
  if (Ans == inf)
    rans[id] = -1;
  else
    rans[id] = Ans + len[id];
}
int main() {
  int ps = 1, nxt, tmp, Len;
  scanf("%s", s + 1);
  read(n);
  for (int i = 1; i <= n; i++) {
    read(m[i]);
    scanf("%s", t + 1);
    len[i] = strlen(t + 1);
    id = i;
    if (len[i] >= LEN) {
      fz();
      continue;
    }
    insert(t, len[id]);
  }
  bfs();
  dfs(1);
  ps = 1;
  Len = strlen(s + 1);
  for (int i = 1; i <= Len; i++) {
    nxt = s[i] - 'a';
    ps = son[nxt][ps];
    tmp = ps;
    while (tmp != 1) g[tmp].emplace_back(i), tmp = fa[tmp];
  }
  for (int i = 1; i <= n; i++) {
    if (rans[i] != 0) continue;
    if ((int)(g[end[i]].size()) < m[i]) {
      rans[i] = -1;
      continue;
    }
    int Ans = inf;
    for (int j = m[i]; j <= (int)(g[end[i]].size()); j++)
      Ans = std::min(Ans, g[end[i]][j - 1] - g[end[i]][j - m[i]]);
    rans[i] = Ans + len[i];
  }
  for (int i = 1; i <= n; i++) printf("%d\n", rans[i]);
}
