#include <bits/stdc++.h>
using namespace std;
int const ALPHA = 26;
struct Node {
  int to[ALPHA];
  bool leaf;
  int link;
  int ext;
  int lvl;
  int idx;
  Node() {
    leaf = link = ext = lvl = 0;
    idx = -1;
    for (int i = 0; i < ALPHA; i++) to[i] = 0;
  }
};
vector<Node> t(1);
void add(string &s, int id) {
  int v = 0;
  for (auto ch : s) {
    if (!t[v].to[ch - 'a']) {
      t[v].to[ch - 'a'] = t.size();
      t.push_back(Node());
    }
    v = t[v].to[ch - 'a'];
  }
  t[v].leaf = 1;
  t[v].idx = id;
}
void build_aho() {
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (int ch = 0; ch < ALPHA; ch++) {
      int v = t[p].to[ch];
      if (v) {
        t[v].link = (p == 0) ? 0 : t[t[p].link].to[ch];
        if (t[t[v].link].leaf) {
          t[v].ext = t[v].link;
        } else {
          t[v].ext = t[t[v].link].ext;
        }
        t[v].lvl = t[p].lvl + 1;
        q.push(v);
      } else {
        t[p].to[ch] = t[t[p].link].to[ch];
      }
    }
  }
}
vector<int> g[100010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<pair<int, string>> q(n);
  for (int i = 0; i < n; i++) {
    cin >> q[i].first >> q[i].second;
    add(q[i].second, i);
  }
  build_aho();
  int cur = 0;
  for (int i = 0; i < s.size(); i++) {
    cur = t[cur].to[s[i] - 'a'];
    int temp = cur;
    while (temp != 0) {
      if (t[temp].leaf) g[t[temp].idx].push_back(i);
      temp = t[temp].ext;
    }
  }
  for (int i = 0; i < n; i++) {
    if (g[i].size() < q[i].first)
      cout << -1 << "\n";
    else {
      sort(g[i].begin(), g[i].end());
      int mn = 1e8;
      for (int j = q[i].first - 1; j < g[i].size(); j++) {
        mn = min(
            mn, (int)(g[i][j] - g[i][j - q[i].first + 1] + q[i].second.size()));
      }
      cout << mn << "\n";
    }
  }
  return 0;
}
