#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 9;
const long long maxn = 4e5 + 7;
const double pi = acos(-1.0);
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = (long long)a * a % M)
    if (b & 1) ret = (long long)ret * a % M;
  return ret;
}
int ans[maxn];
struct SAM {
  int next[maxn][26], fail[maxn], len[maxn];
  int cnt, last;
  void init() {
    cnt = last = 0;
    fail[0] = -1;
    len[0] = 0;
    memset(next[0], 0, sizeof(next[0]));
  }
  void add(int c) {
    int np = ++cnt, p = last;
    memset(next[np], 0, sizeof(next[np]));
    len[np] = len[p] + 1;
    for (; p != -1 && !next[p][c]; p = fail[p]) next[p][c] = np;
    if (p == -1)
      fail[np] = 0;
    else {
      int q = next[p][c];
      if (len[p] + 1 == len[q])
        fail[np] = q;
      else {
        int nq = ++cnt;
        len[nq] = len[p] + 1;
        memcpy(next[nq], next[q], sizeof(next[q]));
        fail[nq] = fail[q];
        fail[np] = fail[q] = nq;
        for (; p != -1 && next[p][c] == q; p = fail[p]) next[p][c] = nq;
      }
    }
    last = np;
    pos[last].insert(len[np]);
  }
  int S[maxn], Q[maxn];
  set<int> pos[maxn];
  vector<pair<int, int> > queries[maxn];
  void solve() {
    int t, i, j;
    for (i = 1; i <= cnt; i++) S[i] = 0;
    for (i = 1; i <= cnt; i++) S[len[i]]++;
    for (i = 1; i <= cnt; i++) S[i] += S[i - 1];
    for (i = 1; i <= cnt; i++) Q[S[len[i]]--] = i;
    for (t = cnt; t >= 1; t--) {
      i = Q[t];
      map<int, int> MP;
      vector<int> V;
      if (queries[i].size()) {
        for (int v : pos[i]) V.push_back(v);
      }
      for (auto now : queries[i]) {
        if ((int)pos[i].size() - now.first < 0)
          ans[now.second] = -1;
        else if (MP[now.first])
          ans[now.second] += MP[now.first];
        else {
          int Ans = INF, len = (int)V.size() - now.first + 1;
          for (j = 0; j < len; j++) Ans = min(Ans, V[j + now.first - 1] - V[j]);
          MP[now.first] = Ans;
          ans[now.second] += Ans;
        }
      }
      int k = fail[i];
      if (pos[k].size() < pos[i].size()) pos[k].swap(pos[i]);
      for (int v : pos[i]) pos[k].insert(v);
      set<int>().swap(pos[i]);
    }
  }
  void query(char a[], int k, int pos) {
    int i;
    long long ret = 0;
    int n = strlen(a), p = 0;
    for (i = 0; i < n; i++) {
      int c = a[i] - 'a';
      if (next[p][c])
        p = next[p][c];
      else {
        ans[pos] = -1;
        return;
      }
    }
    queries[p].push_back(make_pair(k, pos));
  }
  void print() {
    int i;
    for (i = 1; i <= cnt; i++) {
    }
  }
  char a[maxn];
  void dfs(int x = 0, int len = 0) {
    int i;
    for (i = 0; i < 26; i++) {
      if (next[x][i]) {
        a[len] = i + 'a';
        dfs(next[x][i], len + 1);
        a[len] = 0;
      }
    }
  }
} sam;
int n, q;
char A[maxn];
int main() {
  int i, j, k;
  scanf("%s", A);
  n = strlen(A);
  sam.init();
  for (i = 0; i < n; i++) sam.add(A[i] - 'a');
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    int k;
    scanf("%d%s", &k, A);
    ans[i] = strlen(A);
    sam.query(A, k, i);
  }
  sam.solve();
  for (i = 0; i < q; i++) printf("%d\n", ans[i]);
  return 0;
}
