#include <bits/stdc++.h>
using namespace std;
const int ms = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int trie[ms][26], sz = 0, link[ms], cnt[ms], save[ms];
vector<int> term[ms], fans[ms];
void insert(string s, int idx) {
  int node = 0;
  for (auto c : s) {
    if (trie[node][c - 'a'] == -1) trie[node][c - 'a'] = ++sz;
    node = trie[node][c - 'a'];
  }
  term[node].push_back(idx);
}
vector<int> m_merge(vector<int> &a, vector<int> &b) {
  vector<int> ans(int(a.size()) + int(b.size()));
  merge(a.begin(), a.end(), b.begin(), b.end(), ans.begin());
  ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
  return ans;
}
void build_links() {
  queue<int> q;
  q.push(0);
  link[0] = 0;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (int ch = 0; ch < 26; ch++) {
      int &to = trie[node][ch];
      int f = node == 0 ? 0 : trie[link[node]][ch];
      if (to == -1) {
        to = f;
      } else {
        link[to] = f;
        q.push(to);
        term[to] = m_merge(term[to], term[f]);
      }
    }
  }
}
void search(string s) {
  int node = 0;
  for (int i = 0; i < s.size(); i++) {
    node = trie[node][s[i] - 'a'];
    for (auto v : term[node]) fans[v].push_back(i);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  string s;
  cin >> s;
  int n, x;
  cin >> n;
  string t;
  memset(trie, -1, sizeof trie);
  for (int i = 0; i < n; i++) {
    cin >> x >> t;
    insert(t, i);
    cnt[i] = x;
    save[i] = t.size();
  }
  build_links();
  search(s);
  for (int i = 0; i < n; i++) {
    int ff = inf;
    for (int j = 0; j + cnt[i] - 1 < fans[i].size(); j++)
      ff = min(ff, fans[i][j + cnt[i] - 1] - fans[i][j] + save[i]);
    if (ff == inf) ff = -1;
    cout << ff << endl;
  }
  return 0;
}
