#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
const int INF = 1e9;
queue<int> q[maxn];
int ch[maxn][26];
int f[maxn], val[maxn], last[maxn];
int a[maxn], len[maxn];
int ans[maxn];
char s[maxn], t[maxn];
int m, tot;
void init() {
  fill(ans, ans + maxn, INF);
  tot = 0;
}
void insert(char *s, int len_s, int pos) {
  len[pos] = len_s;
  int u = 0;
  for (int i = 0; i < len_s; i++) {
    int id = s[i] - 'a';
    if (!ch[u][id]) ch[u][id] = ++tot;
    u = ch[u][id];
  }
  val[u] = pos;
}
void build_ac() {
  queue<int> q0;
  q0.push(0);
  while (!q0.empty()) {
    int u = q0.front();
    q0.pop();
    int r = f[u];
    for (int i = 0; i < 26; i++) {
      int v = ch[u][i];
      if (!v) {
        ch[u][i] = ch[r][i];
        continue;
      }
      q0.push(v);
      f[v] = u ? ch[r][i] : 0;
      last[v] = val[f[v]] ? f[v] : last[f[v]];
    }
  }
}
void solve() {
  init();
  scanf("%s", s);
  int len_s = strlen(s);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %s", &a[i], t);
    insert(t, strlen(t), i);
  }
  build_ac();
  int u = 0;
  for (int i = 0; i < len_s; i++) {
    int id = s[i] - 'a';
    u = ch[u][id];
    if (val[u] || last[u]) {
      int now = val[u] ? u : last[u];
      while (now) {
        int pos = val[now];
        q[pos].push(i);
        if (q[pos].size() >= a[pos]) {
          int r = q[pos].front();
          q[pos].pop();
          ans[pos] = min(ans[pos], (i - r) + len[pos]);
        }
        now = last[now];
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", (ans[i] == INF) ? -1 : ans[i]);
  }
}
int main() {
  solve();
  return 0;
}
