#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, kk[N], trie[N][26], fail[N], idx, w[N], len[N];
vector<int> p[N];
char s[N], ss[N];
void insert(int id) {
  int pos = 0;
  len[id] = strlen(s + 1);
  for (int i = 1; i <= len[id]; i++) {
    if (!trie[pos][s[i] - 'a']) trie[pos][s[i] - 'a'] = ++idx;
    pos = trie[pos][s[i] - 'a'];
  }
  w[pos] = id;
}
void build() {
  queue<int> q;
  for (int i = 0; i < 26; i++)
    if (trie[0][i]) q.push(trie[0][i]);
  while (!q.empty()) {
    int nd = q.front();
    q.pop();
    for (int i = 0; i < 26; i++)
      if (trie[nd][i])
        fail[trie[nd][i]] = trie[fail[nd]][i], q.push(trie[nd][i]);
      else
        trie[nd][i] = trie[fail[nd]][i];
  }
  for (int i = 1; i <= idx; i++)
    while (fail[i] && !w[fail[i]]) fail[i] = fail[fail[i]];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> (ss + 1) >> n;
  int m = strlen(ss + 1);
  for (int i = 1; i <= n; i++) {
    cin >> kk[i] >> (s + 1);
    insert(i);
  }
  build();
  int cur = 0;
  for (int i = 1; i <= m; i++) {
    cur = trie[cur][ss[i] - 'a'];
    for (int j = cur; j != 0; j = fail[j])
      if (w[j]) p[w[j]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (int(p[i].size()) < kk[i]) {
      cout << -1 << endl;
      continue;
    }
    int ans = m;
    for (int j = 0, k = kk[i] - 1; k < int(p[i].size()); j++, k++)
      ans = min(ans, p[i][k] - (p[i][j] - len[i]));
    cout << ans << endl;
  }
  return 0;
}
