#include <bits/stdc++.h>
using namespace std;
long long SIGMA = 26;
struct ac_node {
  long long pch;
  long long p = -1;
  long long link = -1;
  long long out_link = -1;
  long long leaf = -1;
  vector<long long> next;
  ac_node(long long P = -1, long long PCH = -1) {
    p = P, pch = PCH;
    next = vector<long long>(SIGMA, -1);
  }
};
struct AhoCora {
  vector<ac_node> tr;
  AhoCora() { tr.emplace_back(-1, -1); }
  void insert_string(string &s, long long idx) {
    long long v = 0, i = 0;
    long long ch;
    while (i < s.length()) {
      ch = s[i] - 'a';
      if (tr[v].next[ch] != -1) {
        v = tr[v].next[ch];
      } else {
        tr.emplace_back(v, ch);
        tr[v].next[ch] = tr.size() - 1;
        v = tr.size() - 1;
      }
      i++;
    }
    tr[v].leaf = idx;
  }
  void construct_links(long long v) {
    if (!v) {
      tr[v].link = 0;
      tr[v].out_link = 0;
      return;
    }
    if (!tr[v].p) {
      tr[v].link = 0;
      if (tr[v].leaf != -1)
        tr[v].out_link = v;
      else
        tr[v].out_link = 0;
      return;
    }
    long long u = tr[tr[v].p].link;
    long long ch = tr[v].pch;
    while (true) {
      if (tr[u].next[ch] != -1) {
        tr[v].link = tr[u].next[ch];
        break;
      }
      if (!u) {
        tr[v].link = 0;
        break;
      }
      u = tr[u].link;
    }
    if (tr[v].leaf != -1)
      tr[v].out_link = v;
    else
      tr[v].out_link = tr[tr[v].link].out_link;
  }
  void build() {
    queue<long long> q;
    q.push(0);
    while (!q.empty()) {
      long long v = q.front();
      q.pop();
      construct_links(v);
      for (long long i = 0; i < SIGMA; ++i) {
        if (tr[v].next[i] != -1) q.push(tr[v].next[i]);
      }
    }
  }
  void pattern_matching(string &t, vector<vector<long long>> &matches) {
    long long m = t.length();
    long long v = 0, ch;
    for (long long i = 0; i < m; ++i) {
      ch = t[i] - 'a';
      while (true) {
        if (tr[v].next[ch] != -1) {
          v = tr[v].next[ch];
          break;
        }
        if (!v) break;
        v = tr[v].link;
      }
      long long u = v;
      while (true) {
        u = tr[u].out_link;
        if (!u) break;
        assert(tr[u].leaf != -1);
        matches[tr[u].leaf].push_back(i);
        u = tr[u].link;
      }
    }
  }
};
int32_t main() {
  string s;
  cin >> s;
  long long n;
  cin >> n;
  AhoCora T;
  vector<vector<long long>> matches(n);
  vector<long long> k(n);
  vector<long long> len(n);
  for (long long i = 0; i < n; ++i) {
    cin >> k[i];
    string mi;
    cin >> mi;
    len[i] = mi.length();
    T.insert_string(mi, i);
  }
  T.build();
  T.pattern_matching(s, matches);
  for (long long i = 0; i < n; ++i) {
    if (matches[i].size() < k[i]) {
      cout << -1 << '\n';
      continue;
    }
    long long ans = INT_MAX;
    for (long long j = k[i] - 1; j < matches[i].size(); ++j) {
      ans = min(ans, matches[i][j] - matches[i][j - k[i] + 1] + len[i]);
    }
    cout << ans << '\n';
  }
}
