#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
struct info {
  bool query;
  int cnt;
  char ch;
  info *fth, *link;
  info *fewiuf[26];
  bool isNext[26];
  vector<int> pos;
  info(info *_fth, char _ch) {
    query = false;
    cnt = 0;
    ch = _ch - 'a';
    fth = _fth;
    link = nullptr;
    memset(fewiuf, 0, sizeof fewiuf);
    memset(isNext, 0, sizeof(isNext));
  }
};
int k[100010], len[100010];
string s, m;
info *queryIdx[100010], *q[100010];
info *add(info *node, string s) {
  for (auto ch : s) {
    if (!node->fewiuf[ch - 'a']) {
      node->fewiuf[ch - 'a'] = new info(node, ch);
      node->isNext[ch - 'a'] = true;
    }
    node = node->fewiuf[ch - 'a'];
  }
  node->query = true;
  return node;
}
info *getLink(info *node);
info *go(info *node, char ch);
void bfs(info *root);
int main() {
  int i, n;
  info *root, *node;
  root = new info(nullptr, 0);
  cin >> s >> n;
  for (i = 0; i < n; ++i) {
    cin >> k[i] >> m;
    len[i] = m.size();
    queryIdx[i] = add(root, m);
  }
  for (node = root, i = 0; i < s.length(); ++i) {
    node = go(node, s[i] - 'a');
    node->pos.push_back(i);
  }
  bfs(root);
  for (i = 0; i < n; ++i) {
    node = queryIdx[i];
    if (node->pos.size() < k[i])
      cout << -1 << '\n';
    else {
      sort(node->pos.begin(), node->pos.end());
      int j, ans = 2000000010;
      for (j = 0; j + k[i] - 1 < node->pos.size(); ++j)
        ans = min(ans, node->pos[j + k[i] - 1] - node->pos[j] + len[i]);
      cout << ans << '\n';
    }
  }
  return 0;
}
info *getLink(info *node) {
  if (node->link) return node->link;
  if (!node->fth) return node->link = node;
  if (!node->fth->fth) return node->link = node->fth;
  return node->link = go(getLink(node->fth), node->ch);
}
info *go(info *node, char ch) {
  if (node->fewiuf[ch]) return node->fewiuf[ch] = node->fewiuf[ch];
  if (!node->fth) return node->fewiuf[ch] = node;
  return node->fewiuf[ch] = go(getLink(node), ch);
}
void bfs(info *root) {
  int i, l, r;
  for (q[0] = root, l = r = 0; l <= r; ++l) {
    q[l]->query |= getLink(q[l])->query;
    for (i = 0; i < 26; ++i)
      if (q[l]->isNext[i]) q[++r] = q[l]->fewiuf[i];
  }
  for (i = r; i > 0; --i) {
    if (!q[i]->query) continue;
    for (auto p : q[i]->pos) getLink(q[i])->pos.push_back(p);
  }
}
