#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct Aho {
  enum { ALPHA = 30 };
  struct Node {
    int p = -1, link = -1, superLink = -1;
    int next[ALPHA], go[ALPHA];
    bool leaf = false;
    vector<int> leaves;
    char ch;
    Node(int p = -1, char c = '$') : p(p), ch(c) {
      fill(begin(next), end(next), -1);
      fill(begin(go), end(go), -1);
    }
  };
  vector<Node> nodes;
  void insert(string &s, int id) {
    int v = 0;
    for (char ch : s) {
      int c = ch - 'a';
      if (nodes[v].next[c] == -1) {
        Node aux = Node(v, ch);
        nodes[v].next[c] = (int)nodes.size();
        nodes.push_back(aux);
      }
      v = nodes[v].next[c];
    }
    nodes[v].leaf = true;
    nodes[v].leaves.push_back(id);
  }
  int go(int v, char ch) {
    int c = ch - 'a';
    if (nodes[v].go[c] == -1) {
      if (nodes[v].next[c] != -1) {
        nodes[v].go[c] = nodes[v].next[c];
      } else {
        if (v == 0)
          nodes[v].go[c] = 0;
        else
          nodes[v].go[c] = go(nodes[v].link, ch);
      }
    }
    return nodes[v].go[c];
  }
  Aho(vector<string> &vs) {
    Node root = Node();
    nodes.push_back(root);
    int id = 0;
    for (auto s : vs) insert(s, id++);
    queue<int> fila;
    nodes[0].link = 0;
    for (int &v : nodes[0].next) {
      if (v != -1) {
        fila.push(v);
        nodes[v].link = 0;
      } else
        v = 0;
    }
    while (!fila.empty()) {
      int v = fila.front();
      fila.pop();
      for (int u : nodes[v].next) {
        if (u != -1) {
          int c = nodes[u].ch - 'a';
          int fail = nodes[v].link;
          while (nodes[fail].next[c] == -1) {
            fail = nodes[fail].link;
          }
          fail = nodes[fail].next[c];
          for (int id : nodes[fail].leaves) {
            nodes[u].leaves.push_back(id);
          }
          nodes[u].link = fail;
          fila.push(u);
        }
      }
    }
  }
  int find(int idx, int p) {
    if (idx != p and (nodes[idx].leaf or idx == 0)) return idx;
    if (nodes[idx].superLink == -1) {
      nodes[idx].superLink = find(nodes[idx].link, p);
    }
    return nodes[idx].superLink;
  }
  vector<vector<int> > findAll(string s, int n) {
    vector<vector<int> > res(n + 5);
    int idx = 0;
    for (int i = 0; i < (int)s.size(); i++) {
      char ch = s[i];
      idx = go(idx, ch);
      for (int id : nodes[idx].leaves) res[i].push_back(id);
    }
    return res;
  }
};
string s;
string ss[100005];
int n;
int k[100005];
int32_t main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(0);
  cin >> s >> n;
  vector<string> vs;
  for (int i = 0; i < n; i++) {
    cin >> k[i] >> ss[i];
    vs.push_back(ss[i]);
  }
  Aho ac = Aho(vs);
  auto res = ac.findAll(s, (int)s.size());
  vector<vector<int> > pos(n + 5);
  for (int i = 0; i < (int)res.size(); i++) {
    for (int idx : res[i]) {
      pos[idx].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    int res = 0x3f3f3f3f;
    if ((int)pos[i].size() < k[i]) {
      cout << -1 << '\n';
      continue;
    }
    for (int j = 0; j + k[i] <= (int)pos[i].size(); j++) {
      res = min(res, pos[i][k[i] + j - 1] - pos[i][j] + (int)ss[i].size());
    }
    cout << res << '\n';
  }
  return 0;
}
