#include <bits/stdc++.h>
using namespace std;
const int K = 26;
struct Vertex {
  char pch;
  int next[K];
  int p = -1;
  int suff = -1;
  int dfsin;
  int dfsout;
  int is_leaf = -1;
  int nearest_leaf = -1;
  bool visited = false;
  vector<int> rsuff;
  Vertex(int p = -1, char ch = '$') : p(p), pch(ch) {
    rsuff.clear();
    fill(begin(next), end(next), -1);
  }
};
vector<Vertex> t(1);
int timer;
void add_string(string s, int id) {
  int v = 0;
  for (char ch : s) {
    int c = ch - 'a';
    if (t[v].next[c] == -1) {
      t[v].next[c] = t.size();
      t.emplace_back(v, ch);
    }
    v = t[v].next[c];
  }
  t[v].is_leaf = id;
}
int go(int v, char ch);
int get_suff(int v) {
  if (t[v].suff == -1) {
    if (v == 0 || t[v].p == 0) {
      t[v].suff = 0;
      if (v != 0) t[t[v].suff].rsuff.push_back(v);
    } else {
      t[v].suff = go(get_suff(t[v].p), t[v].pch);
      if (v != 0) t[t[v].suff].rsuff.push_back(v);
    }
  }
  return t[v].suff;
}
int go(int v, char ch) {
  int c = ch - 'a';
  if (t[v].next[c] != -1) return t[v].next[c];
  if (v == 0) return t[v].next[c] = 0;
  return t[v].next[c] = go(get_suff(v), ch);
}
void dfs(int u) {
  timer++;
  t[u].dfsin = timer;
  t[u].visited = true;
  if (t[u].is_leaf != -1)
    t[u].nearest_leaf = u;
  else
    t[u].nearest_leaf = t[t[u].suff].nearest_leaf;
  for (auto v : t[u].rsuff) dfs(v);
  timer++;
  t[u].dfsout = timer;
}
void buildAC(vector<string> patterns) {
  for (int i = 0; i < patterns.size(); i++) add_string(patterns[i], i);
  for (int i = 0; i < t.size(); i++)
    if (t[i].suff == -1) {
      int x = get_suff(i);
    }
  for (int i = 0; i < t.size(); i++)
    if (t[i].visited == false) dfs(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string text;
  cin >> text;
  int n;
  cin >> n;
  vector<int> k(n + 1);
  vector<string> patterns(n + 1);
  for (int i = 1; i <= n; i++) cin >> k[i] >> patterns[i];
  buildAC(patterns);
  vector<int> app[n + 10];
  for (int i = 0; i < n; i++) app[i].clear();
  vector<int> ans(n + 1, -1);
  int v = 0;
  for (int i = 0; i < text.size(); i++) {
    v = go(v, text[i]);
    int cur = v;
    while (1) {
      if (cur == 0) break;
      int id = t[t[cur].nearest_leaf].is_leaf;
      if (id == -1) break;
      int l = patterns[id].size();
      app[id].push_back(i - l + 1);
      if (app[id].size() >= k[id]) {
        int st = app[id][app[id].size() - k[id]];
        if (ans[id] == -1)
          ans[id] = i - st + 1;
        else
          ans[id] = min(ans[id], i - st + 1);
      }
      cur = t[t[cur].nearest_leaf].suff;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << endl;
  return 0;
}
