#include <bits/stdc++.h>
template <typename T1, typename T2>
inline bool chkmin(T1& x, const T2& y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chkmax(T1& x, const T2& y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
using namespace std;
const int maxn = 2e5 + 20;
ostream& operator<<(ostream& out, vector<int>& v) {
  for (auto& x : v) out << x << ' ';
  return out;
}
ostream& operator<<(ostream& out, pair<int, int>& v) {
  out << v.first << ", " << v.second;
  return out;
}
istream& operator>>(istream& in, pair<int, int>& a) {
  in >> a.first >> a.second;
  return in;
}
const long long inf = (long long)2e9;
const long double pi = asin(1) * 2;
const long double eps = 1e-8;
const long long mod = (long long)1e9 + 7;
const long long ns = 97;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct tree {
  map<char, tree*> t;
  tree* p;
  tree* suf;
  tree* ssuf;
  int term, j;
  char last;
  tree() {
    p = suf = ssuf = nullptr;
    term = 0;
    last = '#';
    j = -1;
  }
  tree(tree* x, char r) {
    last = r;
    p = x;
    suf = ssuf = nullptr;
    term = 0;
    j = -1;
  }
};
void add(tree* root, string& s, int j, int i = 0) {
  if (i == (int)s.size()) {
    ++root->term;
    root->j = j;
    return;
  }
  if (!root->t.count(s[i])) root->t[s[i]] = new tree(root, s[i]);
  add(root->t[s[i]], s, j, i + 1);
}
tree* root = nullptr;
void bfs() {
  queue<tree*> a;
  a.push(root);
  root->p = root->ssuf = root;
  while (!a.empty()) {
    auto v = a.front();
    auto c = v->last;
    a.pop();
    auto u = v->p->ssuf;
    while (1) {
      if (u->t.count(c) && u->t[c] != v) {
        v->ssuf = u->t[c];
        break;
      }
      if (u == root) {
        v->ssuf = u;
        break;
      }
      u = u->ssuf;
    }
    for (auto& u : v->t) {
      a.push(u.second);
    }
  }
  a.push(root);
  while (!a.empty()) {
    auto v = a.front();
    a.pop();
    auto u = v->ssuf;
    while (1) {
      if (u == root || u->term) {
        v->suf = u;
        break;
      }
      u = u->suf;
    }
    for (auto& u : v->t) {
      a.push(u.second);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  root = new tree();
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<pair<int, string>> kek(q);
  for (int i = 0; i < q; ++i) {
    int x;
    string t;
    cin >> x >> t;
    kek[i] = {x, t};
    add(root, t, i);
  }
  bfs();
  tree* r = root;
  vector<vector<int>> lol(q);
  for (int i = 0; i < (int)s.size(); ++i) {
    char c = s[i];
    while (1) {
      if (r->t.count(c)) {
        r = r->t[c];
        break;
      }
      if (r == root) break;
      r = r->ssuf;
    }
    auto t = r;
    if (t->j == -1) t = t->suf;
    while (t->j != -1) {
      ;
      ;
      lol[t->j].push_back(i);
      t = t->suf;
    }
  }
  vector<int> ans(q);
  for (int i = 0; i < q; ++i) {
    int k = kek[i].first;
    auto& v = lol[i];
    if ((int)v.size() < k) {
      ans[i] = -1;
      continue;
    }
    int b = k - 1;
    int res = inf;
    while (b < (int)v.size()) {
      chkmin(res, v[b] - v[b - k + 1]);
      ++b;
    }
    res += (int)kek[i].second.size();
    ans[i] = res;
  }
  for (auto& x : ans) cout << x << '\n';
}
