#include <bits/stdc++.h>
using namespace std;
int const MAX = 2e5 + 41;
int const INF = 1e9 + 41;
int const MAGIC = 150;
string s;
int q;
int k[MAX];
string vs[MAX];
int n;
int ans[MAX];
int pref[MAX];
string str;
vector<int> pos;
void build(string s1) {
  str = s1;
  str += "#";
  str += s;
  pref[0] = 0;
  for (int i = 1; i <= (int)str.size() - 1; i++) {
    pref[i] = pref[i - 1];
    while (pref[i] > 0 && str[pref[i]] != str[i]) {
      pref[i] = pref[pref[i] - 1];
    }
    if (str[i] == str[pref[i]]) pref[i]++;
  }
  pos.clear();
  for (int i = (int)s1.size(); i <= (int)str.size() - 1; i++) {
    if (pref[i] >= (int)s1.size()) pos.push_back(i);
  }
}
int solvelarge(string s1, int k) {
  build(s1);
  int res = INF;
  if ((int)pos.size() < k) return res;
  for (int i = k - 1; i <= (int)pos.size() - 1; i++) {
    int x = pos[i];
    int y = pos[i - k + 1] - (int)s1.size() + 1;
    res = min(res, x - y + 1);
  }
  return res;
}
int const P1 = 41;
int const MOD1 = 1000003241;
int const P2 = 541;
int const MOD2 = 1000004119;
int add(int a, int b, int MOD) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
  return a;
}
int mult(int a, int b, int MOD) { return (long long)a * b % MOD; }
unsigned long long gethash(string &s) {
  int res1 = 0;
  int res2 = 0;
  for (int i = 0; i <= (int)s.size() - 1; i++) {
    res1 = mult(res1, P1, MOD1);
    res1 = add(res1, s[i] - 'a' + 1, MOD1);
    res2 = mult(res2, P2, MOD2);
    res2 = add(res2, s[i] - 'a' + 1, MOD2);
  }
  return (unsigned long long)res1 * MOD2 + res2;
}
unordered_map<unsigned long long, int> hh;
vector<int> poses[MAX];
void solvesmall() {
  for (int i = 0; i <= (int)s.size() - 1; i++) {
    int cur1 = 0;
    int cur2 = 0;
    for (int j = 0; j <= MAGIC - 1; j++) {
      if (i + j >= (int)s.size()) break;
      cur1 = mult(cur1, P1, MOD1);
      cur1 = add(cur1, s[i + j] - 'a' + 1, MOD1);
      cur2 = mult(cur2, P2, MOD2);
      cur2 = add(cur2, s[i + j] - 'a' + 1, MOD2);
      unsigned long long cur = (unsigned long long)cur1 * MOD2 + cur2;
      if (hh.find(cur) != hh.end()) {
        poses[hh[cur]].push_back(i + j);
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    if ((int)poses[i].size() >= k[i]) {
      for (int j = k[i] - 1; j <= (int)poses[i].size() - 1; j++) {
        int x = poses[i][j];
        int y = poses[i][j - k[i] + 1] - (int)vs[i].size() + 1;
        ans[i] = min(ans[i], x - y + 1);
      }
    }
  }
}
void solve() {
  for (int i = 1; i <= q; i++) {
    ans[i] = INF;
  }
  for (int i = 1; i <= q; i++) {
    if ((int)vs[i].size() <= MAGIC) {
      unsigned long long h = gethash(vs[i]);
      hh[h] = i;
    } else {
      ans[i] = solvelarge(vs[i], k[i]);
    }
  }
  solvesmall();
  for (int i = 1; i <= q; i++) {
    if (ans[i] == INF) ans[i] = -1;
    printf("%d\n", ans[i]);
  }
}
int main() {
  cin >> s;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> k[i] >> vs[i];
  }
  solve();
  return 0;
}
