#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
template <typename T>
inline void cmin(T &x, T y) {
  if (y < x) x = y;
}
template <typename T>
inline void cmax(T &x, T y) {
  if (x < y) x = y;
}
char s[MAXN], t[MAXN];
int n, m, k[MAXN], len[MAXN];
int tot, ch[MAXN][26], fail[MAXN], ed[MAXN], ff[MAXN];
int q[MAXN], head, tail;
vector<int> mtch[MAXN];
void Insert(int id) {
  int p = 0, l = len[id] = strlen(t + 1);
  for (int i = 1; i <= l; ++i) {
    int x = t[i] - 'a';
    if (!ch[p][x]) {
      ch[p][x] = ++tot;
    }
    p = ch[p][x];
  }
  ed[p] = id;
}
void GetFail() {
  head = 1, tail = 0;
  for (int i = 0; i < 26; ++i) {
    if (ch[0][i]) {
      q[++tail] = ch[0][i];
    }
  }
  while (head <= tail) {
    int u = q[head++];
    for (int i = 0; i < 26; ++i) {
      if (ch[u][i]) {
        int v = ch[u][i];
        fail[v] = ch[fail[u]][i];
        ff[v] = (ed[fail[v]] ? fail[v] : ff[fail[v]]);
        q[++tail] = v;
      } else {
        ch[u][i] = ch[fail[u]][i];
      }
    }
  }
}
void Run() {
  int p = 0;
  for (int i = 1; i <= n; ++i) {
    p = ch[p][s[i] - 'a'];
    int u = (ed[p] ? p : ff[p]);
    for (; u; u = ff[u]) {
      mtch[ed[u]].push_back(i);
    }
  }
}
void init() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  read(m);
  for (int i = 1; i <= m; ++i) {
    read(k[i]);
    scanf("%s", t + 1);
    Insert(i);
  }
  GetFail();
}
void solve() {
  Run();
  for (int i = 1; i <= m; ++i) {
    if (mtch[i].size() < k[i]) {
      printf("-1\n");
    } else {
      int ans = n + 1;
      for (int j = 0, sz = mtch[i].size(); j + k[i] - 1 < sz; ++j) {
        cmin(ans, mtch[i][j + k[i] - 1] - mtch[i][j]);
      }
      printf("%d\n", ans + len[i]);
    }
  }
}
int main() {
  init();
  solve();
  return 0;
}
