#include <bits/stdc++.h>
using namespace std;
struct tn {
  tn *c[26], *f, *s;
  unsigned long long l, id;
};
template <size_t S>
struct pool_t {
  tn* p;
  unsigned long long s;
  pool_t() {
    p = (tn*)malloc(S * sizeof(tn));
    s = 0;
  }
  tn* get(const tn& w) {
    tn* np = p + (s++);
    *np = w;
    return np;
  }
  ~pool_t() { free(p); }
};
pool_t<100000> pool;
struct aca_t {
  tn* r;
  aca_t() : r(0) {}
  tn* get() { return pool.get({{0}, r, 0, 0, 0}); }
  void build(const vector<string>& sv) {
    r = get();
    for (int i = 0; i != sv.size(); ++i) {
      tn* p = r;
      for (const char& ch : sv[i]) {
        int o = ch - 'a';
        if (!p->c[o]) p->c[o] = get();
        p = p->c[o];
      }
      p->id = i + 1;
    }
    queue<tn*> q;
    q.push(r);
    while (q.size()) {
      tn* u = q.front();
      q.pop();
      for (int o = 0; o != 26; ++o) {
        tn *&v = u->c[o], *f = u == r ? r : u->f->c[o];
        if (v) {
          v->f = f;
          v->s = v->f->id ? v->f : v->f->s;
          q.push(v);
        } else
          v = f;
      }
    }
  }
  void match(string t, vector<vector<int>>& res) {
    tn* p = r;
    for (int i = 0; i != t.size(); ++i) {
      p = p->c[t[i] - 'a'];
      for (tn* w = p; w; w = w->s)
        if (w->id) res[w->id - 1].push_back(i);
    }
  }
};
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  aca_t aca;
  string t;
  cin >> t;
  int n;
  cin >> n;
  vector<vector<int>> res;
  res.resize(n);
  vector<int> kv;
  vector<string> sv;
  for (int i = 0; i != n; ++i) {
    int k;
    string s;
    cin >> k >> s;
    kv.push_back(k);
    sv.push_back(s);
  }
  aca.build(sv);
  aca.match(t, res);
  vector<int> ans;
  for (int i = 0; i != n; ++i) {
    int k = kv[i];
    if (res[i].size() < k)
      ans.push_back(-1);
    else {
      int d = ~(1 << 31);
      for (int j = 0; j != res[i].size(); ++j)
        if (j >= k - 1) d = min(d, res[i][j] - res[i][j - k + 1]);
      ans.push_back(d + sv[i].size());
    }
  }
  for (int d : ans) cout << d << endl;
  return 0;
}
