#include <bits/stdc++.h>
using namespace std;
struct aho {
  struct Vertex {
    vector<int> next;
    int par, link, ans, leaf;
    Vertex() {
      next.resize(26);
      fill(next.begin(), next.end(), -1);
      ans = -1;
      leaf = -1;
    }
  };
  vector<Vertex> sh;
  vector<vector<int>> sol;
  aho(int x) {
    sh.emplace_back();
    sol.resize(x);
  }
  void add(char s[], int k, int n) {
    int v = 0;
    for (int i = 0; i < n; i++) {
      int c = s[i] - 'a';
      if (sh[v].next[c] == -1) {
        sh[v].next[c] = sh.size();
        sh.emplace_back();
      }
      v = sh[v].next[c];
    }
    sh[v].leaf = k;
  }
  void find(char s[], int n) {
    int u, v = 0;
    for (int j = 0; j < n; j++) {
      int c = s[j] - 'a';
      while (v && sh[v].next[c] == -1) {
        v = sh[v].link;
      }
      if (~sh[v].next[c])
        v = sh[v].next[c];
      else
        v = 0;
      u = v;
      while (u) {
        if (~sh[u].leaf) sol[sh[u].leaf].push_back(j);
        u = sh[u].ans;
      }
    }
    return;
  }
  int transition(int x, int y) {
    if (~sh[x].next[y]) return sh[x].next[y];
    if (!x) return 0;
    return sh[x].next[y] = transition(sh[x].link, y);
  }
  int cnt(int x) {
    if (~sh[x].ans) return sh[x].ans;
    if (~sh[sh[x].link].leaf) return sh[x].link;
    return sh[x].ans = cnt(sh[x].link);
  }
  void init() {
    queue<int> q;
    q.push(0);
    sh[0].par = 0;
    sh[0].link = 0;
    sh[0].ans = 0;
    int u, v;
    while (!q.empty()) {
      u = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (sh[u].next[i] == -1) continue;
        v = sh[u].next[i];
        sh[v].par = u;
        if (u)
          sh[v].link = transition(sh[u].link, i);
        else
          sh[v].link = 0;
        sh[v].ans = cnt(v);
        q.push(v);
      }
    }
  }
  void check(int n, int k[], int nb[]) {
    int i;
    for (i = 0; i < n; i++) {
      int ans = 100000000;
      for (int j = 0; j + k[i] - 1 < sol[i].size(); j++) {
        ans = min((sol[i][j + k[i] - 1] - sol[i][j]), ans);
      }
      if (ans >= 10000000)
        cout << -1 << endl;
      else
        cout << ans + nb[i] << endl;
    }
  }
};
char s[200005], t[200005];
int k[200005], nb[200005];
int main() {
  int i, j, l, m, n, x, y;
  scanf("%s", s);
  scanf("%d", &n);
  aho sh(n);
  for (i = 0; i < n; i++) {
    scanf("%d", &k[i]);
    getchar();
    scanf("%s", &t);
    nb[i] = strlen(t);
    sh.add(t, i, nb[i]);
  }
  sh.init();
  sh.find(s, strlen(s));
  sh.check(n, k, nb);
  return 0;
}
