#include <bits/stdc++.h>
using namespace std;
struct vec {
  int to;
  int fro;
};
int fa[200010], son[200010][26], mx[200010];
int rt, lst, tot;
int n, m;
char s[200010];
vec mp[200010];
int tai[200010], cnt;
int P[200010];
int ans[200010];
vector<int> qs[200010];
int av[200010];
int len[200010];
int Rt[200010], Son[4000010][2];
int TOT;
inline void be(int x, int y) {
  mp[++cnt].to = y;
  mp[cnt].fro = tai[x];
  tai[x] = cnt;
}
int merge(int x, int y) {
  if (!x || !y) {
    return x + y;
  }
  Son[x][0] = merge(Son[x][0], Son[y][0]);
  Son[x][1] = merge(Son[x][1], Son[y][1]);
  return x;
}
void change(int &x, int y, int z, int p) {
  if (!x) {
    x = ++TOT;
  }
  if (y == z) {
    return;
  }
  int mid = y + z >> 1;
  if (p <= mid) {
    change(Son[x][0], y, mid, p);
  } else {
    change(Son[x][1], mid + 1, z, p);
  }
}
void ins(int x) {
  int np = ++tot, p = lst;
  mx[np] = mx[p] + 1;
  while (p && !son[p][x]) {
    son[p][x] = np;
    p = fa[p];
  }
  if (!p) {
    fa[np] = rt;
  } else {
    int q = son[p][x];
    if (mx[q] == mx[p] + 1) {
      fa[np] = q;
    } else {
      int nq = ++tot;
      mx[nq] = mx[p] + 1;
      memcpy(son[nq], son[q], sizeof(son[q]));
      fa[nq] = fa[q];
      fa[np] = fa[q] = nq;
      while (p && son[p][x] == q) {
        son[p][x] = nq;
        p = fa[p];
      }
    }
  }
  lst = np;
}
int L;
int t[200010];
void DFS(int x, int y, int z) {
  if (y == z) {
    t[++L] = y;
    return;
  }
  int mid = y + z >> 1;
  if (Son[x][0]) {
    DFS(Son[x][0], y, mid);
  }
  if (Son[x][1]) {
    DFS(Son[x][1], mid + 1, z);
  }
}
void dfs(int x) {
  int i, y;
  for (i = tai[x]; i; i = mp[i].fro) {
    y = mp[i].to;
    dfs(y);
  }
  for (i = tai[x]; i; i = mp[i].fro) {
    y = mp[i].to;
    Rt[x] = merge(Rt[x], Rt[y]);
  }
  L = 0;
  if (qs[x].size()) {
    L = 0;
    DFS(Rt[x], 1, n);
    for (i = 0; i < qs[x].size(); i++) {
      int wzh = 1;
      int ti = qs[x][i];
      int tav = av[qs[x][i]];
      if (L < tav) {
        ans[ti] = -1;
      } else {
        ans[ti] = 1000000000;
        for (int j = tav; j <= L; j++) {
          ans[ti] = min(ans[ti], t[j] - t[j - tav + 1] + len[ti]);
        }
      }
    }
  }
}
int main() {
  int i, x;
  lst = rt = tot = 1;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int p = rt;
  for (i = 1; i <= n; i++) {
    ins(s[i] - 'a');
    p = son[p][s[i] - 'a'];
    P[i] = p;
    change(Rt[p], 1, n, i);
  }
  for (i = 2; i <= tot; i++) {
    be(fa[i], i);
  }
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%s", &av[i], s + 1);
    int p = rt;
    for (int j = 1; s[j]; j++) {
      p = son[p][s[j] - 'a'];
    }
    len[i] = strlen(s + 1);
    if (!p) {
      ans[i] = -1;
    } else {
      qs[p].push_back(i);
    }
  }
  dfs(1);
  for (i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
