#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 1e9 + 9;
unsigned long long Hash[100011];
unsigned long long P = 29;
unsigned long long p_pow[100011];
const int MAXN = 1e5 + 5;
int n;
int q;
string s;
vector<int> poses[100001];
int k[100001];
string strs[100001];
vector<int> queries[100001];
map<unsigned long long, int> have;
inline void solve(int x) {
  for (int i = 0; i < queries[x].size(); i++) {
    unsigned long long _Hash = 0;
    string cur = strs[queries[x][i]];
    for (int j = 1; j <= x; j++) {
      _Hash += (unsigned long long)(cur[j - 1] - 'a' + 1) * p_pow[j] % MOD;
      _Hash %= MOD;
    }
    _Hash *= p_pow[MAXN - x];
    _Hash %= MOD;
    have[_Hash] = queries[x][i];
  }
  for (int i = 1; i <= n - x + 1; i++) {
    unsigned long long tmp = (MOD + Hash[i + x - 1] - Hash[i - 1]) % MOD;
    tmp *= p_pow[MAXN - (i + x - 1)];
    tmp %= MOD;
    if (have.count(tmp)) poses[have[tmp]].push_back(i);
  }
  have.clear();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = s.length();
  p_pow[0] = 1;
  for (int i = 1; i <= MAXN; i++) p_pow[i] = p_pow[i - 1] * P % MOD;
  for (int i = 1; i <= n; i++) {
    Hash[i] = Hash[i - 1] + (unsigned long long)(s[i - 1] - 'a' + 1) * p_pow[i];
    Hash[i] %= MOD;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> k[i];
    cin >> strs[i];
    queries[strs[i].length()].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (queries[i].size() > 0) {
      solve(i);
    }
  for (int i = 1; i <= q; i++) {
    if (poses[i].size() < k[i]) {
      cout << -1 << '\n';
      continue;
    }
    int len = 2e9;
    int cur;
    for (int j = k[i] - 1; j < poses[i].size(); j++) {
      cur = poses[i][j] + (int)strs[i].size() - poses[i][j - k[i] + 1];
      if (cur < len) len = cur;
    }
    cout << len << '\n';
  }
  return 0;
}
