#include <bits/stdc++.h>
using namespace std;
int n, k[100005], Next[100005][27], cnt, out[100005], link[100005];
vector<int> id[100005], res[100005];
string s, t[100005];
void Add(string s, int x) {
  int u = 0;
  for (int i = 0; s[i]; i++) {
    int v = s[i] - 'a';
    if (!Next[u][v]) Next[u][v] = ++cnt;
    u = Next[u][v];
  }
  out[u]++;
  id[u].push_back(x);
}
int get_next(int u, int k) {
  while (u != -1) {
    if (Next[u][k]) return Next[u][k];
    u = link[u];
  }
  return 0;
}
void Bfs() {
  queue<int> q;
  q.push(0);
  link[0] = -1;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int p = (0); p <= (25); p++) {
      if (Next[u][p]) {
        int v = Next[u][p];
        link[v] = get_next(link[u], p);
        q.push(v);
        out[v] += out[link[v]];
        copy(id[link[v]].begin(), id[link[v]].end(), back_inserter(id[v]));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s;
  cin >> n;
  for (int i = (1); i <= (n); i++) {
    cin >> k[i] >> t[i];
    Add(t[i], i);
  }
  Bfs();
  int p = 0;
  for (int i = 0; s[i]; i++) {
    p = get_next(p, s[i] - 'a');
    for (int u : id[p]) res[u].push_back(i);
  }
  for (int i = (1); i <= (n); i++) {
    if (res[i].size() < k[i]) {
      cout << -1 << '\n';
      continue;
    }
    int low = 1e9;
    for (int j = (k[i] - 1); j <= (res[i].size() - 1); j++) {
      low = min(low, res[i][j] - res[i][j - k[i] + 1]);
    }
    cout << low + t[i].size() << '\n';
  }
}
