#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
pair<int, int> pr[N];
vector<int> v, occ[N];
int node[N][28], fail[N], path[N], end_pos[N], res[N], cnt, sz, up[N];
void insert(string s, int pos) {
  int now = 0;
  for (int i = 0; i < s.size(); i++) {
    if (!node[now][s[i] - 'a']) node[now][s[i] - 'a'] = ++cnt;
    now = node[now][s[i] - 'a'];
  }
  end_pos[now] = pos;
}
void failure() {
  queue<int> q;
  for (int i = 0; i < 26; i++)
    if (node[0][i]) q.push(node[0][i]), v.push_back(node[0][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    v.push_back(u);
    for (int i = 0; i < 26; i++) {
      int now = node[u][i];
      if (now) {
        int qq = fail[u];
        while (qq and !node[qq][i]) qq = fail[qq];
        if (u != qq and node[qq][i]) fail[node[u][i]] = node[qq][i];
        q.push(now);
      }
    }
  }
}
void ans(string s) {
  for (auto i : v) {
    if (end_pos[i])
      up[i] = i;
    else
      up[i] = up[fail[i]];
  }
  int now = 0;
  for (int i = 0; i < s.size(); i++) {
    while (now and !node[now][s[i] - 'a']) now = fail[now];
    if (node[now][s[i] - 'a']) now = node[now][s[i] - 'a'];
    int x = up[now];
    while (x) occ[end_pos[x]].push_back(i), x = up[fail[x]];
  }
}
void make_clear() {
  cnt = sz = 0;
  memset(node, 0, sizeof(node));
  memset(end_pos, 0, sizeof(end_pos));
  memset(path, 0, sizeof(path));
  memset(fail, 0, sizeof(fail));
}
int main() {
  int t;
  make_clear();
  int n, m, i, b, j;
  string s, ss;
  cin >> s >> n;
  for (i = 1; i <= n; i++)
    cin >> m >> ss, insert(ss, i), pr[i].first = ss.size(), pr[i].second = m;
  failure();
  ans(s);
  for (i = 1; i <= n; i++) {
    int res = 1e9;
    for (j = 0; j + pr[i].second - 1 < occ[i].size(); j++)
      b = occ[i][j + pr[i].second - 1] - occ[i][j] + pr[i].first,
      res = min(res, b);
    if (res == 1e9) res = -1;
    cout << res << endl;
  }
  return 0;
}
