#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
static constexpr int INF = (int)1e9 + 5;
static constexpr ll INFL = (ll)INF * INF;
static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(
                       chrono::high_resolution_clock::now().time_since_epoch())
                       .count());
namespace snippets_ahocorasick {
template <size_t K>
using AcTree = vector<array<int, K>>;
template <size_t K, class Iter, class F>
int ac_add(AcTree<K>& t, Iter it, Iter it_end, F f) {
  if (!((int)(t).size())) t.emplace_back(), t.back().fill(-1);
  int v = 0;
  while (it != it_end) {
    int i = f(*it++);
    if (t[v][i] == -1)
      t[v][i] = ((int)(t).size()), t.emplace_back(), t.back().fill(-1);
    v = t[v][i];
  }
  return v;
}
template <size_t K>
int ac_add(AcTree<K>& t, string_view s, char base) {
  return ac_add(t, (s).begin(), (s).end(), [&](char c) { return c - base; });
}
template <size_t K, class F>
void ac_finalize(AcTree<K>& t, F on_node) {
  if (!((int)(t).size())) return;
  queue<array<int, 4>> q;
  q.push({0, -1, -1, -1});
  while (((int)(q).size())) {
    auto [v, c, p, plink] = q.front();
    q.pop();
    int link = (!v || !p ? 0 : t[plink][c]);
    on_node(v, link, c, p);
    for (int i = 0; i < (K); ++i) {
      if (t[v][i] == -1)
        t[v][i] = (v ? t[link][i] : 0);
      else
        q.push({t[v][i], i, v, link});
    }
  }
}
}  // namespace snippets_ahocorasick
using namespace snippets_ahocorasick;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int n;
  cin >> s >> n;
  vector<pair<int, string>> q(n);
  AcTree<26> t;
  vvi ends;
  for (int i = 0; i < (n); ++i) {
    auto& [ki, si] = q[i];
    cin >> ki >> si;
    int v = ac_add(t, si, 'a');
    if (v >= ((int)(ends).size())) ends.resize(v + 1);
    ends[v].push_back(i);
  }
  ac_finalize(t, [&](int v, int link, int, int) {
    copy((ends[link]).begin(), (ends[link]).end(), back_inserter(ends[v]));
  });
  vi ans(n, INF);
  vector<queue<int>> qs(n);
  int v = 0;
  for (int i = 0; i < (((int)(s).size())); ++i) {
    v = t[v][s[i] - 'a'];
    for (auto& j : ends[v]) {
      qs[j].push(i);
      if (((int)(qs[j]).size()) == q[j].first) {
        int k = qs[j].front();
        qs[j].pop();
        ans[j] = min(ans[j], i - k + ((int)(q[j].second).size()));
      }
    }
  }
  for (int i = 0; i < (n); ++i) cout << (ans[i] == INF ? -1 : ans[i]) << '\n';
  return 0;
}
