#include <bits/stdc++.h>
using namespace std;
int k[100010], N, M, len[100010];
char S[300005], buf[300005];
vector<int> v[100010];
struct NODE {
  NODE() : is_end(0), count(0), f(0), o(0), num(0) {
    for (int i = 0; i < 26; i++) nxt[i] = 0;
  }
  bool is_end;
  int count, num;
  NODE *nxt[26], *f, *o;
} * root;
NODE *my_end_node[100005];
int main() {
  int j;
  scanf("%s%d", S + 1, &M);
  N = strlen(S + 1);
  root = new NODE();
  for (int i = 1; i <= M; i++) {
    scanf("%d", &k[i]);
    scanf("%s", buf + 1);
    int n = strlen(buf + 1);
    len[i] = n;
    NODE *now = root;
    for (int j = 1; j <= n; j++) {
      int c = buf[j] - 'a';
      if (!now->nxt[c]) now->nxt[c] = new NODE();
      now = now->nxt[c];
    }
    now->is_end = 1;
    now->num = i;
    my_end_node[i] = now;
  }
  queue<NODE *> que;
  for (int i = 0; i < 26; i++)
    if (root->nxt[i]) {
      root->nxt[i]->f = root;
      que.push(root->nxt[i]);
    }
  while (!que.empty()) {
    NODE *q = que.front();
    que.pop();
    if (q->is_end)
      q->o = q;
    else
      q->o = q->f->o;
    for (int i = 0; i < 26; i++)
      if (q->nxt[i]) {
        NODE *t = q->nxt[i];
        t->f = q->f;
        while (t->f != root && !t->f->nxt[i]) t->f = t->f->f;
        if (t->f->nxt[i]) t->f = t->f->nxt[i];
        que.push(t);
      }
  }
  NODE *now = root;
  NODE *now2 = root;
  for (int i = 1; i <= N; i++) {
    int c = S[i] - 'a';
    while (now != root && !now->nxt[c]) now = now->f;
    if (now->nxt[c]) now = now->nxt[c];
    if (now->o) {
      now2 = now->o;
      while (now2 && now2->o) {
        v[now2->o->num].push_back(i);
        if (now2->o->num == 40) {
          j = 1;
        }
        if (now2->o == now2) {
          now2 = now2->f->o;
        } else
          now2 = now2->o;
      }
      now->o->count++;
    }
  }
  for (int i = 1; i <= M; i++) {
    int mini = 2147483647;
    for (j = k[i] - 1; j < v[i].size(); j++) {
      if (mini > v[i][j] - v[i][j - k[i] + 1] + len[i])
        mini = v[i][j] - v[i][j - k[i] + 1] + len[i];
    }
    if (mini == 2147483647)
      printf("-1\n");
    else
      printf("%d\n", mini);
  }
}
