#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
  putchar(' ');
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
template <typename R, typename D>
inline void Min(R &a, D b) {
  if (a > b) a = b;
}
template <typename D, typename R>
inline void Max(D &a, R b) {
  if (a < b) a = b;
}
const int N = 100005, C = 26;
int k, top, bot, o[N], id[N];
string t[N];
vector<int> ve[N];
struct Trie {
  int last;
  Trie *link;
  Trie *child[C];
  Trie() {
    last = 0;
    for (int i = 0; i < C; ++i) child[i] = NULL;
    link = NULL;
  }
} trie;
Trie *q[N];
void Reset() {
  Trie *p = &trie;
  for (int i = 0; i < 26; ++i) {
    p->child[i] = NULL;
  }
  top = bot = 1;
}
void Add(string s, int id) {
  Trie *p = &trie;
  for (int i = 0; i < s.size(); ++i) {
    int tmp = s[i] - 'a';
    if (p->child[tmp] == NULL) p->child[tmp] = new Trie();
    p = p->child[tmp];
  }
  p->last = id;
}
void Aho() {
  while (bot <= top) {
    Trie *u = q[bot++], *v;
    for (int p = 0; p < C; ++p) {
      v = u->child[p];
      if (v == NULL) continue;
      Trie *nl = u->link;
      for (;;) {
        if (nl == NULL) break;
        if (nl->child[p] != NULL) {
          nl = nl->child[p];
          break;
        }
        nl = nl->link;
      }
      if (nl == NULL) nl = &trie;
      v->link = nl;
      q[++top] = v;
    }
  }
}
void Find(string s) {
  Trie *p = &trie;
  for (int i = 0; i < s.size(); ++i) {
    int tmp = s[i] - 'a';
    for (;;) {
      if (p->child[tmp] != NULL) {
        p = p->child[tmp];
        break;
      }
      p = p->link;
      if (p == NULL) {
        p = &trie;
        break;
      }
    }
    if (p->last) ve[p->last].push_back(i);
  }
}
int Handle(int i) {
  if (ve[i].size() < o[i]) return -1;
  int res = 2e9;
  for (int j = o[i] - 1; j < ve[i].size(); ++j) {
    Min(res, ve[i][j] - ve[i][j - o[i] + 1]);
  }
  return res + t[i].size();
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> o[i] >> t[i];
    id[i] = i;
  }
  sort(id + 1, id + 1 + k,
       [&](int x, int y) { return t[x].size() < t[y].size(); });
  q[top = 1] = &trie;
  int run = 1;
  while (run <= k) {
    int tr = t[id[run]].size();
    Reset();
    while (t[id[run]].size() == tr) {
      Add(t[id[run]], id[run]);
      ++run;
    }
    Aho();
    Find(s);
  }
  for (int i = 1; i <= k; ++i) {
    cout << Handle(i) << '\n';
  }
  return 0;
}
