#include <bits/stdc++.h>
using namespace std;
char str[100001];
struct tn {
  tn *c[26], *f, *s;
  vector<unsigned> p;
  unsigned l, i, sz;
} ns[100001], *np;
struct aca_t {
  tn* r;
  aca_t() { np = ns; }
  tn* gn() { return np++; }
  void build(unsigned n) {
    r = gn();
    for (unsigned i = 0; i != n; ++i) {
      tn* p = r;
      unsigned l;
      string t;
      cin >> l >> t;
      for (const char& ch : t) {
        unsigned o = ch - 'a';
        if (!p->c[o]) p->c[o] = gn();
        p = p->c[o];
      }
      p->l = l;
      p->i = i;
      p->sz = t.size();
    }
    queue<tn*> q;
    for (tn*& v : r->c) v ? q.push(v), v->f = r : v = r;
    while (!q.empty()) {
      tn* u = q.front();
      q.pop();
      for (unsigned o = 0; o != 26; ++o) {
        tn *&v = u->c[o], *f = u->f->c[o];
        if (v) {
          v->f = f;
          q.push(v);
          if (f->sz)
            v->s = f;
          else
            v->s = f->s;
        } else
          v = f;
      }
    }
  }
  void match(char* s) {
    tn* p = r;
    for (unsigned i = 0; s[i]; ++i) {
      unsigned o = s[i] - 'a';
      p = p->c[o];
      for (tn* w = p; w; w = w->s) w->p.push_back(i);
    }
  }
} aca;
unsigned ans[100001];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> str;
  unsigned n;
  cin >> n;
  aca.build(n);
  aca.match(str);
  memset(ans, 0xff, sizeof(ans));
  for (tn* p = ns; p != np; ++p) {
    if (p->l && p->p.size() >= p->l) {
      for (unsigned i = 0; i <= p->p.size() - p->l; ++i)
        ans[p->i] = min(ans[p->i], p->p[i + p->l - 1] - p->p[i]);
      ans[p->i] += p->sz;
    }
  }
  for (unsigned i = 0; i != n; ++i) cout << (int)ans[i] << endl;
  return 0;
}
