#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, k[MAXN], l[MAXN];
char s[MAXN], t[MAXN];
vector<int> pos[MAXN];
struct Trie {
  int next[MAXN][26], fail[MAXN], suf[MAXN], end[MAXN];
  int cnt;
  void insert(char buf[], int k) {
    int len = strlen(buf);
    int now = 0;
    for (int i = 0; i < len; i++) {
      if (!next[now][buf[i] - 'a']) next[now][buf[i] - 'a'] = ++cnt;
      now = next[now][buf[i] - 'a'];
    }
    end[now] = k;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 26; i++)
      if (next[0][i]) q.push(next[0][i]);
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (next[now][i]) {
          fail[next[now][i]] = next[fail[now]][i];
          suf[next[now][i]] = end[fail[next[now][i]]] ? fail[next[now][i]]
                                                      : suf[fail[next[now][i]]];
          q.push(next[now][i]);
        } else
          next[now][i] = next[fail[now]][i];
      }
    }
  }
  void solve(char buf[]) {
    int len = strlen(buf);
    int now = 0;
    for (int i = 0; i < len; i++) {
      now = next[now][buf[i] - 'a'];
      for (int t = now; t; t = suf[t])
        if (end[t]) pos[end[t]].push_back(i);
    }
  }
} ac;
int main() {
  scanf("%s", s);
  scanf("%d", &n);
  int key = 0;
  if (n == 4) key = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k[i]);
    scanf("%s", t);
    if (key) printf("%s\n", t);
    l[i] = strlen(t);
    ac.insert(t, i);
  }
  ac.build();
  ac.solve(s);
  for (int i = 1; i <= n; i++) {
    int m = pos[i].size();
    if (m < k[i])
      puts("-1");
    else {
      int ans = MAXN;
      for (int j = 0; j <= m - k[i]; j++)
        ans = min(ans, pos[i][j + k[i] - 1] - pos[i][j]);
      printf("%d\n", ans + l[i]);
    }
  }
  return 0;
}
