#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char S[N], T[N];
const int BLOCK = 100;
int BIG(int k) {
  string s(S), t(T);
  s = t + "#" + s;
  int n = s.size(), m = t.size();
  vector<int> p(n);
  for (int i = 1; i < n; i++) {
    int j = p[i - 1];
    while (j > 0 and s[i] != s[j]) {
      j = p[j - 1];
    }
    if (s[i] == s[j]) j++;
    p[i] = j;
  }
  vector<int> v;
  for (int i = m + m; i < n; i++) {
    if (p[i] == m) v.emplace_back(i);
  }
  if (v.size() < k) return -1;
  int ans = 1e9;
  for (int i = k - 1; i < v.size(); i++) {
    ans = min(ans, v[i] - v[i - k + 1]);
  }
  return ans + m;
}
int ans[N];
struct state {
  int to[26];
  int depth;
  int suffLink;
  int par;
  int parLet;
  int nxt[26];
} states[N];
int totNodes = 1;
int add(char *str) {
  int cur = 1;
  int len = strlen(str);
  for (int i = 0; i < len; i++) {
    char c = str[i];
    if (!states[cur].to[c - 'a']) {
      states[cur].to[c - 'a'] = ++totNodes;
      states[totNodes].par = cur;
      states[totNodes].depth = states[cur].depth + 1;
      states[totNodes].parLet = c - 'a';
    }
    cur = states[cur].to[c - 'a'];
  }
  return cur;
}
int who[N];
int kk[N];
vector<int> g[N];
void pushLinks() {
  queue<int> Q;
  Q.push(1);
  while (!Q.empty()) {
    int node = Q.front();
    Q.pop();
    if (states[node].depth <= 1) {
      states[node].suffLink = 1;
    } else {
      int cur = states[states[node].par].suffLink;
      int parLet = states[node].parLet;
      while (cur > 1 and !states[cur].to[parLet]) {
        cur = states[cur].suffLink;
      }
      if (states[cur].to[parLet]) {
        cur = states[cur].to[parLet];
      }
      states[node].suffLink = cur;
    }
    if (node != 1) g[states[node].suffLink].push_back(node);
    for (int i = 0; i < 26; i++) {
      if (states[node].to[i]) {
        Q.push(states[node].to[i]);
      }
    }
  }
}
vector<int> idx[N];
vector<int> nodes;
vector<int> pos[N];
void dfs(int u, int p) {
  if (who[u]) {
    nodes.push_back(who[u]);
  }
  for (auto id : idx[u]) {
    for (auto v : nodes) {
      pos[v].emplace_back(id);
    }
  }
  for (auto v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
  }
  if (who[u]) {
    nodes.pop_back();
  }
}
int sz[N];
int main() {
  scanf("%s", S);
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int k;
    scanf("%d %s", &k, &T);
    int m = strlen(T);
    if (m > BLOCK) {
      ans[i] = BIG(k);
    } else {
      who[add(T)] = i;
      kk[i] = k;
      sz[i] = m;
    }
  }
  pushLinks();
  int len = strlen(S);
  int cur = 1;
  for (int i = 0; i < len; i++) {
    int c = S[i] - 'a';
    while (cur > 1 and !states[cur].to[c]) {
      cur = states[cur].suffLink;
    }
    if (states[cur].to[c]) {
      cur = states[cur].to[c];
    }
    idx[cur].push_back(i);
  }
  dfs(1, -1);
  for (int i = 1; i <= Q; i++) {
    if (!kk[i]) continue;
    int k = kk[i];
    if (pos[i].size() < k) {
      ans[i] = -1;
      continue;
    }
    sort(pos[i].begin(), pos[i].end());
    ans[i] = 1e9;
    for (int j = k - 1; j < pos[i].size(); j++) {
      ans[i] = min(ans[i], pos[i][j] - pos[i][j - k + 1]);
    }
    ans[i] += sz[i];
  }
  for (int i = 1; i <= Q; i++) {
    printf("%d ", ans[i]);
  }
}
