#include <bits/stdc++.h>
using namespace std;
long long ghash(char* th) {
  long long res = 0;
  for (int i = 0; th[i]; i++) {
    res *= 69;
    res += th[i] - 'a';
    res %= 29996224275833;
  }
  return res;
}
bool eq(char* a, char* b) {
  for (int i = 0; a[i] && b[i]; i++)
    if (a[i] != b[i]) return false;
  return true;
}
int n, q;
char s[100100], temp[100100];
char* queries[100100];
int k[100100], sz[100100];
vector<int> pts[100100];
map<long long, vector<int> > fromhash[100100];
bool exists[50000000];
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < 50000000; i++) exists[i] = false;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf(" %d%s", &k[i], temp);
    sz[i] = strlen(temp);
    queries[i] = new char[sz[i] + 1];
    for (int j = 0; j <= sz[i]; j++) queries[i][j] = temp[j];
    long long h = ghash(queries[i]);
    exists[h % 50000000] = true;
    fromhash[sz[i]][h].push_back(i);
  }
  long long pv = 1;
  for (int l = 1; l <= n; l++) {
    pv *= 69;
    pv %= 29996224275833;
    if (!fromhash[l].size()) continue;
    long long cv = 0;
    for (int i = 0; i < l; i++) {
      cv *= 69;
      cv += s[i] - 'a';
      cv %= 29996224275833;
    }
    for (int i = l; i <= n; i++) {
      if (exists[cv % 50000000]) {
        if (fromhash[l][cv].size() == 1) {
          pts[fromhash[l][cv][0]].push_back(i - l);
        } else
          for (long long j : fromhash[l][cv]) {
            if (eq(s + i - l, queries[j])) {
              pts[j].push_back(i - l);
              break;
            }
          }
      }
      if (i == n) break;
      cv *= 69;
      cv += s[i] - 'a';
      cv -= (pv * (long long)(s[i - l] - 'a')) % 29996224275833;
      cv += 29996224275833;
      cv %= 29996224275833;
    }
  }
  for (int i = 0; i < q; i++) {
    if (pts[i].size() < k[i])
      printf("-1\n");
    else {
      int cres = n;
      for (int j = k[i] - 1; j < pts[i].size(); j++) {
        cres = min(cres, pts[i][j] - pts[i][j - k[i] + 1]);
      }
      cres += sz[i];
      printf("%d\n", cres);
    }
  }
}
