#include <bits/stdc++.h>
using namespace std;
char s[100010], ss[100100];
int ll, x[100100], l2;
int pp[100100];
vector<int> vv[200100];
set<int> sss[200100];
int n, ans[100100];
int lll[100100];
namespace SAM {
int mem, np, root;
int len[200100], par[200100];
int trans[200100][26];
void append(int ch) {
  int p = np;
  np = ++mem;
  len[np] = len[p] + 1;
  for (; p && !trans[p][ch]; p = par[p]) trans[p][ch] = np;
  if (!p)
    par[np] = root;
  else {
    int q = trans[p][ch];
    if (len[q] == len[p] + 1)
      par[np] = q;
    else {
      int nq = ++mem;
      par[nq] = par[q];
      par[q] = par[np] = nq;
      memcpy(trans[nq], trans[q], sizeof(trans[nq]));
      len[nq] = len[p] + 1;
      for (; p && trans[p][ch] == q; p = par[p]) trans[p][ch] = nq;
    }
  }
}
void build() {
  np = root = ++mem;
  int i;
  for (i = 1; i <= ll; i++) {
    append(s[i] - 'a'), sss[np].insert(i);
  }
}
}  // namespace SAM
void work(int tt) {
  using SAM::trans;
  int i, now = SAM::root;
  for (i = 1; i <= l2; i++) {
    now = trans[now][ss[i] - 'a'];
  }
  vv[now].push_back(tt);
}
queue<int> q;
int in[200100];
void work2() {
  using SAM::mem;
  using SAM::par;
  int i, j, t;
  vector<int> tmp;
  for (i = 1; i <= mem; i++)
    if (par[i]) in[par[i]]++;
  for (i = 1; i <= mem; i++)
    if (!in[i]) q.push(i);
  while (!q.empty()) {
    t = q.front();
    q.pop();
    if (vv[t].size()) {
      tmp.clear();
      for (auto k : sss[t]) tmp.push_back(k);
    }
    for (auto p : vv[t]) {
      for (i = 0, j = x[p] - 1; j < tmp.size(); i++, j++) {
        ans[p] = min(ans[p], tmp[j] - tmp[i] + lll[p]);
      }
    }
    if (par[t]) {
      if (sss[par[t]].size() < sss[t].size()) swap(sss[par[t]], sss[t]);
      for (auto k : sss[t]) sss[par[t]].insert(k);
      sss[t].clear();
      in[par[t]]--;
      if (!in[par[t]]) q.push(par[t]);
    }
  }
}
int main() {
  int i;
  scanf("%s", s + 1);
  ll = strlen(s + 1);
  SAM::build();
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%s", &x[i], ss + 1);
    l2 = lll[i] = strlen(ss + 1);
    work(i);
  }
  int aefsaf;
  memset(ans, 0x3f, sizeof(ans));
  work2();
  for (i = 1; i <= n; i++) printf("%d\n", ans[i] == 0x3f3f3f3f ? -1 : ans[i]);
  return 0;
}
