#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) { return n | (1LL << i); }
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInverse(long long a) {
  normal(a);
  return modPow(a, 1000000007 - 2);
}
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInverse(b));
}
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
string t, str[100005];
int n, k[100005], last[100005], lagbe[100005], ans[100005];
int term[100005], len[100005], to[100005][26], link[100005], sz = 1,
                                                             dokhol[100005];
vector<int> lvl[100005], vt[100005];
int add_str(string &s) {
  int cur = 0, siz = s.size();
  for (int i = 0; i < siz; i++) {
    char c = s[i];
    if (!to[cur][c - 'a']) {
      to[cur][c - 'a'] = sz++;
      len[to[cur][c - 'a']] = len[cur] + 1;
    }
    cur = to[cur][c - 'a'];
  }
  term[cur] = cur;
  lvl[len[cur]].push_back(cur);
  return cur;
}
void push_links() {
  int que[sz];
  int st = 0, fi = 1;
  que[0] = 0;
  while (st < fi) {
    int V = que[st++];
    int U = link[V];
    if (!term[V]) term[V] = term[U];
    for (int c = 0; c < 26; c++)
      if (to[V][c]) {
        link[to[V][c]] = V ? to[U][c] : 0;
        que[fi++] = to[V][c];
      } else {
        to[V][c] = to[U][c];
      }
  }
}
int result(int node) {
  int res = 1e9;
  if (vt[node].size() < lagbe[node]) res = -1;
  sort(vt[node].begin(), vt[node].end());
  int siz = str[dokhol[node]].size() - 1;
  for (int i = 0; res != -1 && i <= vt[node].size() - lagbe[node]; i++) {
    int tmp = vt[node][i + lagbe[node] - 1] - (vt[node][i] - siz) + 1;
    res = min(res, tmp);
  }
  if (term[link[node]]) {
    for (int i = 0; i < vt[node].size(); i++) {
      vt[term[link[node]]].push_back(vt[node][i]);
    }
  }
  return res;
}
void berkoro() {
  int now = 0, siz = t.size();
  for (int i = 0; i < siz; i++) {
    now = to[now][t[i] - 'a'];
    if (term[now]) vt[term[now]].push_back(i);
  }
  for (int i = 100005 - 1; i >= 1; i--) {
    for (int j = 0, V; j < lvl[i].size(); j++) {
      V = lvl[i][j];
      ans[dokhol[V]] = result(V);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> t;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k[i] >> str[i];
    last[i] = add_str(str[i]);
    dokhol[last[i]] = i;
    lagbe[last[i]] = k[i];
  }
  push_links();
  berkoro();
  for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
  return 0;
}
