#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T& n) {
  char ch;
  int sign = 1;
  while (!isdigit(ch = getchar()))
    if (ch == '-') sign = -1;
  n = ch - '0';
  while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
  n *= sign;
}
const int INF = 1e9 + 7;
const int N = 322222;
int n, m;
char s[N];
int k[N], ans[N];
int rt(1), tt(1), p(1), ch[N][26], pa[N], len[N];
int id[N];
struct edge {
  int to, nxt;
} g[N];
int ghead[N], gtail;
void add(int l, int r) { g[++gtail] = (edge){r, ghead[l]}, ghead[l] = gtail; }
void extend(int first, int pos) {
  int np = ++tt;
  len[np] = len[p] + 1, id[np] = pos;
  for (; p && !ch[p][first]; p = pa[p]) ch[p][first] = np;
  if (!p)
    pa[np] = rt;
  else {
    int q = ch[p][first];
    if (len[q] == len[p] + 1)
      pa[np] = q;
    else {
      int nq = ++tt;
      len[nq] = len[p] + 1;
      memcpy(ch[nq], ch[q], sizeof(ch[q]));
      pa[nq] = pa[q], pa[q] = pa[np] = nq;
      for (; p && ch[p][first] == q; p = pa[p]) ch[p][first] = nq;
    }
  }
  p = np;
}
void dfs(int first, vector<int>& seq) {
  if (id[first]) seq.push_back(id[first]);
  for (int p = ghead[first]; p; p = g[p].nxt) {
    int v = g[p].to;
    dfs(v, seq);
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = (1); i <= (n); ++i) extend(s[i] - 'a', i);
  for (int i = (1); i <= (tt); ++i)
    if (pa[i]) add(pa[i], i);
  read(m);
  for (int i = (1); i <= (m); ++i) {
    read(k[i]), scanf("%s", s + 1);
    int l = strlen(s + 1), cur = rt;
    for (int j = (1); j <= (l); ++j) {
      int first = s[j] - 'a';
      if (!ch[cur][first]) {
        ans[i] = -1;
        break;
      }
      cur = ch[cur][first];
    }
    if (ans[i] != -1) {
      vector<int> seq;
      dfs(cur, seq);
      sort(seq.begin(), seq.end());
      int res = INF;
      for (int t = k[i] - 1; t < seq.size(); ++t)
        res = min(res, seq[t] - seq[t - k[i] + 1]);
      res += l;
      if (res >= INF) res = -1;
      ans[i] = res;
    }
  }
  for (int i = (1); i <= (m); ++i) printf("%d\n", ans[i]);
  return 0;
}
