#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7, INF = 1e6;
int t, n, k[N], sz[N], ind[N], q, ans[N], pos[N];
vector<int> V[N];
vector<pair<int, int> > a;
vector<pair<pair<int, int>, int> > p;
string second;
void search1(string t, int ind) {
  int l = 1, r = n, L = n + 1, R = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    string subs = "";
    for (int i = pos[mid]; i < second.size(); i++) {
      subs += second[i];
      if (subs.size() == t.size()) break;
    }
    if (subs < t) {
      l = mid + 1;
    } else {
      L = mid;
      r = mid - 1;
    }
  }
  l = 1;
  r = n;
  while (l <= r) {
    int mid = (l + r) / 2;
    string subs = "";
    for (int i = pos[mid]; i < second.size(); i++) {
      subs += second[i];
      if (subs.size() == t.size()) break;
    }
    if (subs <= t) {
      l = mid + 1;
      R = mid;
    } else
      r = mid - 1;
  }
  if (L <= R) {
    for (int i = L; i <= R; i++) {
      V[pos[i]].push_back(ind);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> second;
  n = second.size();
  second = '#' + second;
  int Lg = log2(n) + 1;
  for (int i = 1; i <= n; i++) {
    a.push_back({second[i] - 'a', i});
  }
  sort(a.begin(), a.end());
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (!i || a[i].first != a[i - 1].first) cur++;
    ind[a[i].second] = cur;
  }
  for (int i = 1; i <= Lg; i++) {
    p.clear();
    for (int j = 1; j <= n; j++) {
      p.push_back({{ind[j], ind[j + (1 << (i - 1))]}, j});
    }
    sort(p.begin(), p.end());
    cur = 0;
    for (int j = 0; j < n; j++) {
      if (!j || p[j].first.first != p[j - 1].first.first ||
          p[j].first.second != p[j - 1].first.second)
        cur++;
      ind[p[j].second] = cur;
      pos[cur] = p[j].second;
    }
  }
  cin >> q;
  vector<int> a[q + 5];
  for (int i = 1; i <= q; i++) {
    string m;
    ans[i] = INF;
    cin >> k[i] >> m;
    sz[i] = m.size();
    search1(m, i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < V[i].size(); j++) {
      if ((int)a[V[i][j]].size() >= k[V[i][j]] - 1) {
        if (k[V[i][j]] == 1)
          ans[V[i][j]] = sz[V[i][j]];
        else
          ans[V[i][j]] =
              min(ans[V[i][j]],
                  i + sz[V[i][j]] -
                      (int)a[V[i][j]][a[V[i][j]].size() - k[V[i][j]] + 1]);
      }
      a[V[i][j]].push_back(i);
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i] != INF)
      cout << ans[i] << " ";
    else
      cout << -1 << " ";
  }
}
