#include <bits/stdc++.h>
using std ::lower_bound;
using std ::sort;
using std ::unique;
using std ::vector;
template <typename T>
T max(T x, T y) {
  return (x > y) ? x : y;
}
template <typename T>
T min(T x, T y) {
  return (x < y) ? x : y;
}
template <typename T>
bool chkmax(T &x, T y) {
  return (x >= y) ? 0 : (x = y, 1);
}
template <typename T>
bool chkmin(T &x, T y) {
  return (x <= y) ? 0 : (x = y, 1);
}
template <typename T>
T read(T &in) {
  in = 0;
  char ch;
  T f = 1;
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  while (isdigit(ch)) in = in * 10 + ch - '0', ch = getchar();
  return in *= f;
}
static const int max1 = 100000 + 11;
int q;
int k[max1], qlen[max1];
int dlen[max1], dl;
char InS[max1], S[max1], *T[max1];
vector<int> SolveAt[max1];
int ch[max1][26], fail[max1], At[max1], q_fail[max1], nd;
vector<int> App[max1];
void Insert(int id) {
  int p = 0;
  for (int i = (0), ir = (qlen[id] - 1); i <= (ir); ++i) {
    int c = T[id][i] - 'a';
    if (!ch[p][c]) ch[p][c] = ++nd;
    p = ch[p][c];
  }
  At[p] = id;
}
void BuildFail() {
  static int que[max1], *front, *back;
  front = back = que;
  for (int i = (0), ir = (25); i <= (ir); ++i)
    if (ch[0][i]) *(++back) = ch[0][i], fail[ch[0][i]] = 0;
  while (front != back) {
    int x = *(++front);
    q_fail[x] = At[fail[x]] ? fail[x] : q_fail[fail[x]];
    for (int i = (0), ir = (25); i <= (ir); ++i)
      if (ch[x][i]) {
        int np = ch[x][i];
        fail[np] = ch[fail[x]][i];
        *(++back) = np;
      } else
        ch[x][i] = ch[fail[x]][i];
  }
}
void solve(int dnow) {
  memset(At, 0, sizeof(int) * (nd + 1)),
      memset(fail, 0, sizeof(int) * (nd + 1)),
      memset(q_fail, 0, sizeof(int) * (nd + 1));
  for (int i = (0), ir = (nd); i <= (ir); ++i) memset(ch[i], 0, sizeof ch[i]);
  nd = 0;
  for (vector<int>::iterator i = SolveAt[dnow].begin();
       i != SolveAt[dnow].end(); ++i)
    Insert(*i);
  BuildFail();
  static int n = strlen(S);
  int p = 0;
  for (int i = (0), ir = (n - 1); i <= (ir); ++i) {
    p = ch[p][S[i] - 'a'];
    for (int j = p; j; j = q_fail[j])
      if (At[j]) App[At[j]].push_back(i);
  }
}
int GetAns(int id) {
  int k = ::k[id];
  if ((int)App[id].size() < k) return -1;
  int Ans = INT_MAX;
  for (int i = (k - 1), ir = ((int)App[id].size() - 1); i <= (ir); ++i)
    chkmin(Ans, App[id][i] - App[id][i - k + 1]);
  return Ans + qlen[id];
}
int main() {
  scanf("%s", S);
  read(q);
  for (int i = (1), ir = (q); i <= (ir); ++i) {
    read(k[i]), scanf("%s", InS);
    qlen[i] = strlen(InS);
    T[i] = new char[qlen[i]];
    memcpy(T[i], InS, sizeof(char) * qlen[i]);
    dlen[++dl] = qlen[i];
  }
  sort(1 + dlen, 1 + dl + dlen),
      dl = unique(1 + dlen, 1 + dl + dlen) - dlen - 1;
  for (int i = (1), ir = (q); i <= (ir); ++i)
    SolveAt[lower_bound(1 + dlen, 1 + dl + dlen, qlen[i]) - dlen].push_back(i);
  for (int i = (1), ir = (dl); i <= (ir); ++i) solve(i);
  for (int i = (1), ir = (q); i <= (ir); ++i) printf("%d\n", GetAns(i));
  return 0;
}
