#include <bits/stdc++.h>
char s[100010], m[100010];
int len, n;
std::set<int> A[100010];
int ch[100010][26], tot, fail[100010], p[100010], Q[100010], k[100010],
    l[100010], Ans[100010];
void Add(char *s, int pos) {
  int now = 0;
  for (int i = 1; s[i]; ++i) {
    int t = s[i] - 'a';
    if (!ch[now][t]) ch[now][t] = ++tot;
    now = ch[now][t];
  }
  p[now] = pos;
}
void Build() {
  int head = 0, tail = 0;
  for (int i = 0; i < 26; ++i)
    if (ch[0][i]) Q[++tail] = ch[0][i];
  do {
    int u = Q[++head];
    for (int i = 0; i < 26; ++i)
      if (ch[u][i]) {
        fail[Q[++tail] = ch[u][i]] = ch[fail[u]][i];
      } else
        ch[u][i] = ch[fail[u]][i];
  } while (head < tail);
}
int Point[100010], Next[100010], To[100010], q;
void Add_Edge(int u, int v) {
  Next[++q] = Point[u];
  Point[u] = q;
  To[q] = v;
}
void dfs(int u) {
  for (int j = Point[u]; j; j = Next[j]) {
    dfs(To[j]);
    if (A[u].size() < A[To[j]].size()) std::swap(A[u], A[To[j]]);
    for (std::set<int>::iterator i = A[To[j]].begin(); i != A[To[j]].end(); ++i)
      A[u].insert(*i);
  }
  if (p[u]) {
    tot = 0;
    for (std::set<int>::iterator i = A[u].begin(); i != A[u].end(); ++i)
      Q[++tot] = *i;
    int K = k[p[u]];
    if (A[u].size() < K) {
      Ans[p[u]] = -1;
      return;
    }
    Ans[p[u]] = 2147483647;
    for (int i = 1, lim = A[u].size(); i <= tot - K + 1; ++i)
      Ans[p[u]] =
          (Ans[p[u]] < Q[i + K - 1] - Q[i] ? Ans[p[u]] : Q[i + K - 1] - Q[i]);
    Ans[p[u]] += l[p[u]];
  }
}
int main() {
  scanf("%s %d", s + 1, &n);
  len = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %s", &k[i], m + 1);
    l[i] = strlen(m + 1);
    Add(m, i);
  }
  Build();
  int now = 0;
  for (int i = 1; i <= len; ++i) {
    int t = s[i] - 'a';
    now = ch[now][t];
    A[now].insert(i);
  }
  for (int i = 1; i <= tot; ++i) Add_Edge(fail[i], i);
  dfs(0);
  for (int i = 1; i <= n; ++i) printf("%d\n", Ans[i]);
  return 0;
}
