#include <bits/stdc++.h>
using namespace std;
const int chr = 26;
struct node {
  int nxt[chr];
  node() { memset(nxt, -1, sizeof(nxt)); }
};
node T[250005];
int suffix[250005], indx, len, path[250005];
int val[250005], ed[250005], E[250005], sf[250005];
vector<int> v[250005];
struct Aho_Corasick {
  void init() {
    len = indx = 0;
    memset(E, 0, sizeof(E));
    memset(T, 0, sizeof(T));
    memset(suffix, 0, sizeof(suffix));
    memset(val, 0, sizeof(val));
    T[indx] = node();
  }
  void insert(string s, int p) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
      int id = s[i] - 'a';
      if (T[now].nxt[id] == -1) {
        T[now].nxt[id] = ++indx;
        T[indx] = node();
      }
      now = T[now].nxt[id];
    }
    ed[p] = now;
    E[now] = p;
  }
  void reverse_link() {
    queue<int> q;
    for (int i = 0; i < chr; i++) {
      if (T[0].nxt[i] != -1) {
        q.push(T[0].nxt[i]);
      } else
        T[0].nxt[i] = 0;
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < chr; i++) {
        int v = T[u].nxt[i];
        if (v == -1) {
          T[u].nxt[i] = T[suffix[u]].nxt[i];
          continue;
        }
        suffix[v] = T[suffix[u]].nxt[i];
        if (E[suffix[v]])
          sf[v] = suffix[v];
        else
          sf[v] = sf[suffix[v]];
        q.push(v);
        path[len++] = v;
      }
    }
  }
  void search(string s) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
      int id = s[i] - 'a';
      now = T[now].nxt[id];
      val[now]++;
      int nd = now;
      while (nd > 0) {
        if (E[nd]) v[E[nd]].push_back(i + 1);
        nd = sf[nd];
      }
    }
    for (int i = len - 1; i >= 0; i--) {
      val[suffix[path[i]]] += val[path[i]];
    }
  }
} AC;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  string T;
  cin >> T >> n;
  vector<pair<int, string> > vc;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> k >> s;
    vc.push_back({k, s});
    AC.insert(s, i);
  }
  AC.reverse_link();
  AC.search(T);
  for (int i = 1; i <= n; i++) {
    if (val[ed[i]] < vc[i - 1].first)
      cout << "-1\n";
    else {
      int mn = 250005;
      int sz = vc[i - 1].second.size();
      k = vc[i - 1].first;
      for (int j = k - 1; j < v[i].size(); j++) {
        mn = min(mn, v[i][j] - v[i][j - k + 1] + sz);
      }
      cout << mn << "\n";
    }
  }
  return 0;
}
