#include <bits/stdc++.h>
using namespace std;
struct SuffixArray {
  const int L;
  string s;
  vector<vector<int> > P;
  vector<pair<pair<int, int>, int> > M;
  SuffixArray(const string &s)
      : L(s.length()), s(s), P(1, vector<int>(L, 0)), M(L) {
    for (int i = 0; i < L; i++) P[0][i] = int(s[i]);
    for (int skip = 1, level = 1; skip < L; skip *= 2, level++) {
      P.push_back(vector<int>(L, 0));
      for (int i = 0; i < L; i++)
        M[i] =
            make_pair(make_pair(P[level - 1][i],
                                i + skip < L ? P[level - 1][i + skip] : -1000),
                      i);
      sort(M.begin(), M.end());
      for (int i = 0; i < L; i++)
        P[level][M[i].second] = (i > 0 && M[i].first == M[i - 1].first)
                                    ? P[level][M[i - 1].second]
                                    : i;
    }
  }
  vector<int> GetSuffixArray() { return P.back(); }
  int LongestCommonPrefix(int i, int j) {
    int len = 0;
    if (i == j) return L - i;
    for (int k = P.size() - 1; k >= 0 && i < L && j < L; k--) {
      if (P[k][i] == P[k][j]) {
        i += 1 << k;
        j += 1 << k;
        len += 1 << k;
      }
    }
    return len;
  }
};
char s[100005], t[100005];
int rk[100005];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  SuffixArray suffix(s);
  vector<int> v = suffix.GetSuffixArray();
  for (int i = 0; i < v.size(); i++) rk[v[i]] = i;
  int q;
  scanf("%d", &q);
  while (q--) {
    int k;
    scanf("%d", &k);
    scanf("%s", t);
    int m = strlen(t);
    int lo = 0, hi = n - 1, l = -1, r = -1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      int res = strncmp(t, s + rk[mid], m);
      if (res == 0)
        l = mid, hi = mid - 1;
      else if (res < 0)
        hi = mid - 1;
      else
        lo = mid + 1;
    }
    lo = 0, hi = n - 1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      int res = strncmp(t, s + rk[mid], m);
      if (res == 0)
        r = mid, lo = mid + 1;
      else if (res < 0)
        hi = mid - 1;
      else
        lo = mid + 1;
    }
    if (l == -1 || r == -1)
      printf("-1\n");
    else {
      vector<int> v;
      for (int i = l; i <= r; i++) {
        v.push_back(rk[i]);
      }
      sort(v.begin(), v.end());
      l = 0, r = 0;
      int ans = 2e9;
      while (l < v.size()) {
        while (r < v.size() && r - l + 1 < k) r++;
        if (r - l + 1 == k && r < v.size()) ans = min(ans, v[r] - v[l] + m);
        l++;
      }
      if (ans == 2e9) ans = -1;
      printf("%d\n", ans);
    }
  }
}
