#include <bits/stdc++.h>
using namespace std;
const unsigned long long key = 31;
int n, m;
string s;
unsigned long long p[100008];
unsigned long long h[100008];
vector<int> v[100005];
vector<int> vv[100005];
int a[100005];
map<unsigned long long, int> pos;
string b[100005];
inline void build(int len) {
  unsigned long long cur = 0;
  for (int i = 0; i < v[len].size(); ++i) {
    cur = 0;
    for (int j = 0; j < len; ++j)
      cur = (cur + (b[v[len][i]][j] - 'a' + 1) * p[j + 1]);
    cur = (cur * p[100004]);
    pos[cur] = v[len][i];
  }
  for (int i = 1; i <= n - len + 1; ++i) {
    cur = h[i + len - 1] - h[i - 1];
    cur *= p[100005 - i];
    if (pos.count(cur)) vv[pos[cur]].push_back(i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = s.size();
  p[0] = 1;
  for (int i = 1; i <= 100005; ++i) p[i] = p[i - 1] * key;
  for (int i = 1; i <= n; ++i) h[i] = h[i - 1] + (s[i - 1] - 'a' + 1) * p[i];
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i];
    cin >> b[i];
    v[b[i].size()].push_back(i);
  }
  for (int i = 1; i <= n; ++i)
    if (v[i].size() > 0) {
      build(i);
    }
  for (int i = 1; i <= m; ++i) {
    if (vv[i].size() < a[i]) {
      cout << -1 << '\n';
      continue;
    }
    int cur = n;
    int z;
    for (int j = a[i]; j <= vv[i].size(); ++j) {
      z = vv[i][j - 1] - vv[i][j - a[i]] + b[i].size();
      if (z < cur) cur = z;
    }
    cout << cur << '\n';
  }
}
