#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXL = 100005;
int n, m;
char str[MAXL], tmp[MAXL];
int cnt[MAXL], lens[MAXL];
vector<int> res[MAXL];
struct Node {
  int c, id;
  bool ie;
  Node *f, *o, *nxt[26];
  Node() : c{-1}, id{-1}, ie{false}, f{nullptr}, o{nullptr} {
    for (int i = 0; i < 26; ++i) nxt[i] = nullptr;
  }
} * root;
void add_pattern(int order) {
  scanf("%s", tmp + 1);
  int len = strlen(tmp + 1);
  lens[order] = len;
  Node *cur = root;
  for (int i = 1; i <= len; ++i) {
    int ch = tmp[i] - 'a';
    if (!cur->nxt[ch]) {
      cur->nxt[ch] = new Node();
      cur->nxt[ch]->c = ch;
    }
    cur = cur->nxt[ch];
  }
  cur->ie = true;
  cur->id = order;
}
void make_fail() {
  queue<Node *> que;
  for (int i = 0; i < 26; ++i)
    if (root->nxt[i]) {
      root->nxt[i]->f = root;
      que.push(root->nxt[i]);
    }
  while (que.size()) {
    Node *cur = que.front();
    que.pop();
    if (cur->ie)
      cur->o = cur;
    else
      cur->o = cur->f->o;
    for (int i = 0; i < 26; ++i)
      if (cur->nxt[i]) {
        Node *next = cur->nxt[i], *t = cur->f;
        while (t != root && !t->nxt[i]) t = t->f;
        if (t->nxt[i]) t = t->nxt[i];
        next->f = t;
        que.push(next);
      }
  }
}
int main() {
  scanf("%s", str + 1);
  int slen = strlen(str + 1);
  root = new Node();
  root->f = root;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", cnt + i);
    add_pattern(i);
  }
  make_fail();
  Node *cur = root;
  for (int i = 1; i <= slen; ++i) {
    int key = str[i] - 'a';
    while (cur != root && !cur->nxt[key]) cur = cur->f;
    if (cur->nxt[key]) cur = cur->nxt[key];
    if (cur->o) res[cur->o->id].push_back(i);
  }
  vector<Node *> order;
  queue<Node *> que;
  que.push(root);
  while (!que.empty()) {
    Node *cur = que.front();
    que.pop();
    order.push_back(cur);
    for (int i = 0; i < 26; i++)
      if (cur->nxt[i]) que.push(cur->nxt[i]);
  }
  reverse(order.begin(), order.end());
  for (Node *tmp : order)
    if (tmp->ie and tmp->f->o) {
      int u = tmp->f->o->id;
      res[u].insert(res[u].end(), res[tmp->id].begin(), res[tmp->id].end());
    }
  int ans = INF;
  for (int i = 1; i <= n; ++i) {
    ans = INF;
    if (res[i].size() < cnt[i])
      puts("-1");
    else {
      sort(res[i].begin(), res[i].end());
      for (int j = cnt[i] - 1; j < res[i].size(); ++j) {
        ans = min(ans, res[i][j] - res[i][j - cnt[i] + 1] + lens[i]);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
