#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
const long double PI = acos(-1.0);
const long double EPS = 1e-6;
const long long INF = 1e9;
const long long LINF = 1e18;
const long long mod = 1000000009;
const long long MAX = 5e3 + 47;
int magic = 50;
string s;
int cnt = 0;
pair<long long, int> hashes[10000000];
long long pow29[100001];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s;
  int n = s.size();
  magic = min(magic, n);
  for (int i = 0; i < s.size(); i++) s[i] -= 'a', s[i]++;
  pow29[0] = 1;
  for (int i = 1; i <= n; i++) pow29[i] = pow29[i - 1] * 37;
  for (int i = 1; i <= magic; i++) {
    long long hash = 0;
    for (int j = 0; j < i; j++) {
      hash *= 37;
      hash += s[j];
    }
    hashes[cnt++] = {hash, 0};
    for (int j = 0; j < n - i; j++) {
      hash -= pow29[i - 1] * s[j];
      hash *= 37;
      hash += s[j + i];
      hashes[cnt++] = {hash, j + 1};
    }
  }
  sort(hashes, hashes + cnt);
  int q;
  cin >> q;
  while (q--) {
    int num = 0;
    string query;
    cin >> num >> query;
    if (query.size() > n) {
      cout << -1 << endl;
      continue;
    }
    long long Hash1 = 0;
    for (int i = 0; i < query.size(); i++) {
      query[i] -= 'a';
      query[i]++;
      Hash1 *= 37;
      Hash1 += query[i];
    }
    if (query.size() <= magic) {
      int ans = INF;
      auto it = lower_bound(hashes, hashes + cnt, make_pair(Hash1, 0));
      if (it == hashes + cnt) {
        cout << -1 << endl;
        continue;
      }
      int pos = it - hashes;
      for (int i = pos;
           i < cnt - num + 1 && hashes[i + num - 1].first == Hash1 &&
           hashes[i].first == Hash1;
           i++) {
        ans = min(ans, hashes[i + num - 1].second - hashes[i].second);
      }
      if (ans == INF)
        cout << -1 << endl;
      else
        cout << ans + query.size() << endl;
    } else {
      vector<int> hashes;
      int magic = query.size();
      long long hash = 0;
      for (int j = 0; j < magic; j++) {
        hash *= 37;
        hash += s[j];
      }
      if (Hash1 == hash) hashes.push_back(0);
      for (int j = 0; j < n - magic; j++) {
        hash -= pow29[magic - 1] * s[j];
        hash *= 37;
        hash += s[j + magic];
        if (Hash1 == hash) hashes.push_back(j + 1);
      }
      int bestAns = INF;
      for (int i = 0; i < (int)hashes.size() - num + 1; i++) {
        bestAns = min(bestAns, hashes[i + num - 1] - hashes[i]);
      }
      if (bestAns == INF)
        cout << -1 << endl;
      else
        cout << bestAns + query.size() << endl;
    }
  }
  return 0;
}
