#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct node {
  int ptr[26];
  int nxt[26];
  int leaf, link, exlink, p, ch;
  node(int _p = -1, int _ch = -1) {
    p = _p;
    ch = _ch;
    link = exlink = leaf = -1;
    memset(ptr, -1, sizeof(ptr));
    memset(nxt, -1, sizeof(nxt));
  }
};
vector<node> trie(1);
vector<int> pos[N];
string t[N];
string s;
int k[N];
int n;
void add(string s, int val) {
  int cur = 0;
  for (char c : s) {
    if (trie[cur].ptr[c - 'a'] < 0) {
      trie[cur].ptr[c - 'a'] = trie.size();
      trie.push_back(node(cur, c - 'a'));
    }
    cur = trie[cur].ptr[c - 'a'];
  }
  trie[cur].leaf = val;
}
int getlink(int u);
int getnext(int u, int ch) {
  int &res = trie[u].nxt[ch];
  if (res == -1) {
    if (trie[u].ptr[ch] != -1)
      res = trie[u].ptr[ch];
    else if (u == 0)
      res = 0;
    else
      res = getnext(getlink(u), ch);
  }
  return res;
}
int getlink(int u) {
  int &res = trie[u].link;
  int ch = trie[u].ch;
  if (res == -1) {
    if (u == 0 || trie[u].p == 0) return res = 0;
    res = getnext(getlink(trie[u].p), ch);
  }
  return res;
}
int getexlink(int u) {
  int &res = trie[u].exlink;
  if (res == -1) {
    if (u == 0)
      return res = 0;
    else if (trie[getlink(u)].leaf >= 0)
      res = getlink(u);
    else
      res = getexlink(getlink(u));
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k[i] >> t[i];
    add(t[i], i);
  }
  int cur = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    cur = getnext(cur, s[i] - 'a');
    int tmp = cur;
    while (tmp) {
      if (trie[tmp].leaf) pos[trie[tmp].leaf].push_back(i);
      tmp = getexlink(tmp);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (pos[i].size() < k[i]) {
      cout << "-1\n";
      continue;
    }
    int res = 1e9;
    for (int j = 0; j + k[i] <= (int)pos[i].size(); j++)
      res = min(res, pos[i][j + k[i] - 1] - pos[i][j] + (int)t[i].size());
    cout << res << "\n";
  }
  return 0;
}
