#include <bits/stdc++.h>
using namespace std;
const int MAXL = 1e5 + 100;
char second[MAXL];
const int sizz = MAXL + 100;
int nx[sizz][26], spt = 1;
int fl[sizz], efl[sizz], ed[sizz];
int newnode(int len_ = 0) {
  for (int i = 0; i < 26; i++) nx[spt][i] = 0;
  ed[spt] = 0;
  return spt++;
}
int add(char *s, int p, int id) {
  int l = 1;
  for (int i = 0; s[i]; i++) {
    int a = s[i] - 'a';
    (void)0;
    if (nx[p][a] == 0) nx[p][a] = newnode(l);
    p = nx[p][a];
    l++;
  }
  ed[p] = id;
  return p;
}
int q[sizz], qs, qe;
void make_fl(int root) {
  fl[root] = efl[root] = 0;
  qs = qe = 0;
  q[qe++] = root;
  for (; qs != qe;) {
    int p = q[qs++];
    for (int i = 0; i < 26; i++) {
      int t = nx[p][i];
      if (t == 0) continue;
      int tmp = fl[p];
      for (; tmp && nx[tmp][i] == 0;) tmp = fl[tmp];
      fl[t] = tmp ? nx[tmp][i] : root;
      efl[t] = ed[fl[t]] ? fl[t] : efl[fl[t]];
      q[qe++] = t;
    }
  }
}
vector<int> at[MAXL];
void match(int root) {
  int p = root;
  for (int i = 1; second[i]; i++) {
    int a = second[i] - 'a';
    (void)0;
    for (; p && nx[p][a] == 0; p = fl[p])
      ;
    p = p ? nx[p][a] : root;
    for (int t = p; t; t = efl[t]) {
      if (!ed[t]) continue;
      at[ed[t]].push_back(i);
    }
  }
}
int K[MAXL], length[MAXL];
char tmp[MAXL];
int main() {
  scanf("%s", second + 1);
  int N;
  scanf("%d", &N);
  int root = newnode();
  for (int i = 1; i <= N; i++) {
    scanf("%d", &K[i]);
    scanf("%s", tmp);
    int len = strlen(tmp);
    length[i] = len;
    add(tmp, root, i);
  }
  make_fl(root);
  match(root);
  for (int i = 1; i <= N; i++) {
    (void)0;
    if (((int)(at[i]).size()) < K[i]) {
      puts("-1");
      continue;
    }
    int ans = at[i][K[i] - 1] - at[i][0];
    for (int j = K[i]; j < ((int)(at[i]).size()); j++)
      ans = min(ans, at[i][j] - at[i][j - (K[i] - 1)]);
    printf("%d\n", ans + length[i]);
  }
  return 0;
}
