#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
struct node {
  int ch[27], len, fa;
} dian[N];
struct edge {
  int v, nxt;
} e[N];
int n, q, head[N], cnt, las = 1, tot = 1, fl[N], pos[N], ot, x, m, ans;
char s[N], t[N];
void ad(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
void add(int c, int id) {
  int np = ++tot, p = las;
  fl[np] = id;
  dian[np].len = dian[p].len + 1;
  for (; p && !dian[p].ch[c]; p = dian[p].fa) dian[p].ch[c] = np;
  if (!p)
    dian[np].fa = 1;
  else {
    int q = dian[p].ch[c];
    if (dian[q].len == dian[p].len + 1)
      dian[np].fa = q;
    else {
      int nq = ++tot;
      dian[nq] = dian[q];
      dian[nq].len = dian[p].len + 1;
      for (; p && dian[p].ch[c] == q; p = dian[p].fa) dian[p].ch[c] = nq;
      dian[np].fa = nq;
      dian[q].fa = nq;
    }
  }
  las = np;
}
void dfs(int u) {
  if (fl[u]) pos[++ot] = fl[u];
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    dfs(v);
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    add(s[i] - 'a', i);
  }
  for (int i = 2; i <= tot; i++) {
    ad(dian[i].fa, i);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &x);
    scanf("%s", t + 1);
    ot = 0;
    m = strlen(t + 1);
    int u = 1, f = 0;
    for (int j = 1; j <= m; j++) {
      int to = t[j] - 'a';
      u = dian[u].ch[to];
      if (!u) {
        f = 1;
        break;
      }
    }
    if (f) {
      printf("-1\n");
      continue;
    }
    dfs(u);
    sort(pos + 1, pos + 1 + ot);
    ans = 999999999;
    for (int j = x; j <= ot; j++) {
      ans = min(ans, pos[j] - (pos[j - x + 1] - m + 1) + 1);
    }
    if (ans == 999999999) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", ans);
  }
}
