#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
namespace SA {
const int MN = 100010;
int n, k, rsa[MN], tmp[MN];
bool cmp(int i, int j) {
  if (rsa[i] != rsa[j]) return rsa[i] < rsa[j];
  int ri = (i + k <= n) ? rsa[i + k] : -1;
  int rj = (j + k <= n) ? rsa[j + k] : -1;
  return ri < rj;
}
template <class S>
vector<int> build(const S &s) {
  n = int(s.size());
  vector<int> sa(n + 1);
  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    rsa[i] = i < n ? s[i] : -1;
  }
  for (k = 1; k <= n; k *= 2) {
    sort(sa.begin(), sa.end(), cmp);
    tmp[sa[0]] = 0;
    for (int i = 1; i <= n; i++) {
      tmp[sa[i]] = tmp[sa[i - 1]] + int(cmp(sa[i - 1], sa[i]));
    }
    copy(tmp, tmp + n + 1, rsa);
  }
  return sa;
}
}  // namespace SA
template <class S>
pair<int, int> match(const S &s, const S &t, const vector<int> &sa) {
  int n = int(s.size()), m = int(t.size());
  pair<int, int> ans;
  int lw, hi;
  lw = 0;
  hi = n + 1;
  while (hi - lw > 1) {
    int mi = (lw + hi) / 2;
    if (s.compare(sa[mi], m, t) < 0) {
      lw = mi;
    } else {
      hi = mi;
    }
  }
  ans.first = hi;
  lw = 0;
  hi = n + 1;
  while (hi - lw > 1) {
    int mi = (lw + hi) / 2;
    if (s.compare(sa[mi], m, t) <= 0) {
      lw = mi;
    } else {
      hi = mi;
    }
  }
  ans.second = hi;
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<int> sa = SA::build(s);
  int q;
  cin >> q;
  for (int ph = 0; ph < q; ph++) {
    int k;
    string m;
    cin >> k >> m;
    pair<int, int> u = match(s, m, sa);
    vector<int> v;
    for (int i = u.first; i < u.second; i++) {
      v.push_back(sa[i]);
    }
    sort(v.begin(), v.end());
    int n = int(v.size());
    if (n < k) {
      cout << -1 << '\n';
      continue;
    }
    int ans = INF;
    for (int i = 0; i <= n - k; i++) {
      ans = min(ans, v[i + k - 1] - v[i] + int(m.size()));
    }
    cout << ans << '\n';
  }
  return 0;
}
