#include <bits/stdc++.h>
using namespace std;
const int P = 101;
int pot[200005];
struct hstring {
  const string *src;
  vector<int> h;
  hstring() : src(nullptr), h(1) {}
  hstring(const string &str) : src(&str), h(str.size() + 1) {
    for (int i = (int)(0); i < (int)(str.size()); ++i)
      h[i + 1] = h[i] * P + str[i];
  }
  int size() const { return (int)src->size(); }
  char operator[](int first) const { return (*src)[first]; }
  int operator()(int first) const { return h[first]; }
};
struct hstring2 {
  const hstring *src;
  int shift;
  hstring2(hstring &_src, int _shift = 0) : src(&_src), shift(_shift) {}
  int size() const { return src->size() - shift; }
  char operator[](int first) const { return (*src)[first + shift]; }
  int operator()(int first) const {
    return (*src)(first + shift) - (*src)(shift)*pot[first];
  }
};
int lcp(const hstring2 &a, const hstring2 &b) {
  int lo = 0, hi = min(a.size(), b.size()), mid;
  while (lo != hi) {
    mid = (lo + hi + 1) / 2;
    if (a(mid) != b(mid))
      hi = mid - 1;
    else
      lo = mid;
  }
  return lo;
}
bool operator<(const hstring2 &a, const hstring2 &b) {
  int tmp = lcp(a, b);
  if (tmp == a.size()) return b.size() != tmp;
  if (tmp == b.size()) return false;
  return a[tmp] < b[tmp];
}
string s;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  pot[0] = 1;
  for (int i = (int)(0); i < (int)(2e5); ++i) pot[i + 1] = P * pot[i];
  cin >> s;
  hstring hs(s);
  vector<hstring2> suffix;
  for (int i = (int)(0); i < (int)(s.size()); ++i) suffix.emplace_back(hs, i);
  sort(suffix.begin(), suffix.end());
  cin >> n;
  for (int blatruc = (int)(0); blatruc < (int)(n); ++blatruc) {
    int k;
    cin >> k;
    string m;
    cin >> m;
    hstring hm(m);
    hstring2 hm2(hm);
    int sz = (int)m.size();
    vector<int> loc;
    for (auto it = lower_bound(suffix.begin(), suffix.end(), hm2);
         it != suffix.end() && it->size() >= sz && (*it)(sz) == hm(sz); ++it)
      loc.push_back(it->shift);
    if ((int)loc.size() < k) {
      cout << -1 << endl;
      continue;
    }
    sort(loc.begin(), loc.end());
    int sol = 1e9;
    for (int i = (int)(0); i < (int)(loc.size() - k + 1); ++i)
      sol = min(sol, loc[i + k - 1] - loc[i]);
    cout << sol + sz << endl;
  }
  return 0;
}
