#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 1e5 + 3;
string s, m[N];
int n, k[N], link[N];
vector<int> appear[N], occ[N];
struct Trie {
  int ackjalscjaowjico[26], p, pch;
} trie[N];
void add() {
  int nNode = 0;
  for (int i = (1); i <= (n); ++i) {
    int u = 0, j = 0;
    while (j < ((int)(m[i]).size()) &&
           trie[u].ackjalscjaowjico[m[i][j] - 'a'] != -1)
      u = trie[u].ackjalscjaowjico[m[i][j] - 'a'], j++;
    while (j < ((int)(m[i]).size())) {
      trie[u].ackjalscjaowjico[m[i][j] - 'a'] = ++nNode;
      trie[nNode].p = u;
      trie[nNode].pch = m[i][j] - 'a';
      u = nNode;
      j++;
    }
    appear[u].push_back(i);
  }
}
void build_link() {
  queue<int> q;
  link[0] = -1;
  for (int i = (0); i <= (25); ++i)
    if (trie[0].ackjalscjaowjico[i] != -1) q.push(trie[0].ackjalscjaowjico[i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    int p = link[trie[u].p], c = trie[u].pch;
    while (p >= 0 && trie[p].ackjalscjaowjico[c] == -1) p = link[p];
    if (p == -1)
      link[u] = 0;
    else {
      link[u] = trie[p].ackjalscjaowjico[c];
      for (int v : appear[link[u]]) appear[u].push_back(v);
    }
    for (int i = (0); i <= (25); ++i)
      if (trie[u].ackjalscjaowjico[i] != -1)
        q.push(trie[u].ackjalscjaowjico[i]);
  }
}
void find_occ() {
  int u = 0;
  for (int i = (0); i <= (((int)(s).size()) - 1); ++i) {
    while (u >= 0 && trie[u].ackjalscjaowjico[s[i] - 'a'] == -1) u = link[u];
    if (u == -1)
      u = 0;
    else {
      u = trie[u].ackjalscjaowjico[s[i] - 'a'];
      for (int v : appear[u]) occ[v].push_back(i - ((int)(m[v]).size()) + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  for (int i = (0); i <= (N - 3); ++i)
    fill(trie[i].ackjalscjaowjico, trie[i].ackjalscjaowjico + 26, -1);
  cin >> s >> n;
  for (int i = (1); i <= (n); ++i) cin >> k[i] >> m[i];
  add();
  build_link();
  find_occ();
  for (int i = (1); i <= (n); ++i) {
    if (((int)(occ[i]).size()) < k[i])
      cout << "-1\n";
    else {
      int ans = ((int)(s).size());
      for (int j = 0; j <= ((int)(occ[i]).size()) - k[i]; j++)
        ans = min(ans, occ[i][j + k[i] - 1] + ((int)(m[i]).size()) - occ[i][j]);
      cout << ans << '\n';
    }
  }
}
