#include <bits/stdc++.h>
using namespace std;
struct node {
  int ch[26], f, d;
} t[100010];
vector<int> has[100010], to[100010];
int pre[100010];
int tot = 1;
inline void ins(char *s, const int p) {
  int L = strlen(s + 1), x = 1;
  for (int i = 1; i <= L; i++) {
    const int in = s[i] - 'a';
    if (!t[x].ch[in]) t[x].ch[in] = ++tot, t[tot].d = i;
    x = t[x].ch[in];
  }
  has[x].push_back(p);
}
int que[100010];
inline void build(int l = 1, int r = 0) {
  for (int i = 0; i < 26; i++)
    if (t[1].ch[i]) {
      t[t[1].ch[i]].f = 1;
      que[++r] = t[1].ch[i];
    } else
      t[1].ch[i] = 1;
  while (l <= r) {
    const int x = que[l++];
    for (int i = 0; i < 26; i++)
      if (t[x].ch[i]) {
        t[t[x].ch[i]].f = t[t[x].f].ch[i];
        pre[t[x].ch[i]] = has[t[t[x].ch[i]].f].size() ? t[t[x].ch[i]].f
                                                      : pre[t[t[x].ch[i]].f];
        que[++r] = t[x].ch[i];
      } else
        t[x].ch[i] = t[t[x].f].ch[i];
  }
}
vector<int> edp[100010];
inline void match(char *s) {
  int L = strlen(s + 1), x = 1;
  for (int i = 1; i <= L; i++) {
    x = t[x].ch[s[i] - 'a'];
    int y = x;
    while (y) {
      if (has[y].size()) edp[y].push_back(i);
      y = pre[y];
    }
  }
}
char s[100010], T[100010];
int k[100010], ans[100010];
int main() {
  scanf("%s", s + 1);
  const int l = strlen(s + 1);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%s", &k[i], T + 1);
    ins(T, i);
  }
  build();
  match(s);
  memset(ans, 0x3f, sizeof ans);
  for (int i = 1; i <= tot; i++)
    if (has[i].size())
      for (int j : has[i])
        for (int p = 0; p < edp[i].size(); p++)
          if (p >= k[j] - 1)
            ans[j] = min(ans[j], edp[i][p] - edp[i][p - k[j] + 1] + t[i].d);
  for (int i = 1; i <= n; i++) printf("%d\n", ans[i] == ans[0] ? -1 : ans[i]);
}
