#include <bits/stdc++.h>
using namespace std;
const int mxn = 100001, k = 26;
int n, m;
string second, t;
int a[mxn], sz[mxn], lk[mxn], q[mxn];
int tr[mxn][k];
vector<int> v[mxn], first[mxn];
int ql, qr, it = 1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> second >> m;
  n = second.size();
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> t;
    sz[i] = t.size();
    int l = 0;
    for (char c : t) {
      int j = c - 'a';
      if (!tr[l][j]) tr[l][j] = it++;
      l = tr[l][j];
    }
    v[l].push_back(i);
  }
  lk[qr++] = -1;
  while (ql < qr) {
    int c = q[ql++];
    if (~lk[c])
      for (int i : v[lk[c]]) v[c].push_back(i);
    for (int i = 0; i < k; i++) {
      int j = lk[c], l = tr[c][i];
      if (l) {
        lk[l] = ~j ? tr[j][i] : 0;
        q[qr++] = l;
      } else {
        tr[c][i] = tr[j][i];
      }
    }
  }
  for (int i = 0, j = 0; i < n; i++) {
    int c = second[i] - 'a';
    j = tr[j][c];
    for (int l : v[j]) first[l].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    if (first[i].size() < a[i]) {
      cout << -1 << '\n';
    } else {
      int ret = n;
      for (int j = a[i] - 1; j < first[i].size(); j++) {
        ret = min(ret, first[i][j] - first[i][j - a[i] + 1]);
      }
      ret += sz[i];
      cout << ret << '\n';
    }
  }
  return 0;
}
