#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100, INF = 0x3f3f3f3f;
char ax[maxn], bx[maxn];
int id[maxn], ans[maxn], bel[maxn], temp[maxn], val[maxn], L[maxn];
vector<int> ac[maxn];
set<int> ss[maxn];
struct AC_hod {
  int Size = 1;
  struct node {
    int Next[26];
    int fail, cnt, nn, len;
  } Tree[maxn];
  void init() {
    build_newnode(0);
    Size = 1;
  }
  void build_newnode(int now) {
    for (int i = 0; i < 26; i++) Tree[now].Next[i] = 0;
    Tree[now].fail = 0, Tree[now].cnt = 0;
    Tree[now].nn = 0;
  }
  int Insert(char* s, int c) {
    int now = 0, cnt1 = strlen(s);
    for (int i = 0; i < cnt1; i++) {
      if (!Tree[now].Next[s[i] - 'a']) {
        Tree[now].Next[s[i] - 'a'] = Size++;
        build_newnode(Size - 1);
      }
      now = Tree[now].Next[s[i] - 'a'];
    }
    Tree[now].cnt = c, Tree[now].len = cnt1;
    return now;
  }
  void build() {
    int now = 0;
    Tree[now].fail = 0;
    queue<int> Q;
    Q.push(now);
    while (!Q.empty()) {
      now = Q.front();
      Q.pop();
      for (int i = 0; i < 26; i++) {
        int temp = Tree[now].Next[i];
        if (temp) {
          if (now == 0)
            Tree[temp].fail = 0;
          else
            Tree[temp].fail = Tree[Tree[now].fail].Next[i];
          Q.push(temp);
        } else {
          if (!now)
            Tree[now].Next[i] = 0;
          else
            Tree[now].Next[i] = Tree[Tree[now].fail].Next[i];
        }
      }
    }
  }
  void buildTree() {
    for (int i = 1; i <= Size; i++) ac[Tree[i].fail].push_back(i);
  }
  void make(char* s) {
    int len = strlen(s), now = 0, l = 0;
    memset(bel, 0, sizeof(bel));
    for (int i = 0; i < len; i++) {
      int c = s[i] - 'a';
      now = Tree[now].Next[c];
      if (!bel[now]) bel[now] = ++l;
      ss[bel[now]].insert(i);
    }
  }
  void calc(int x) {
    int now = x;
    for (int i = 0; i < ac[x].size(); i++) {
      int v = ac[x][i];
      calc(v);
      if (ss[bel[v]].size() > ss[bel[now]].size()) now = v;
    }
    for (int i = 0; i < ac[x].size(); i++) {
      int v = ac[x][i];
      if (v == now) continue;
      for (auto j = ss[bel[v]].begin(); j != ss[bel[v]].end(); j++) {
        ss[bel[now]].insert(*j);
      }
    }
    if (x != now) {
      for (auto j = ss[bel[x]].begin(); j != ss[bel[x]].end(); j++)
        ss[bel[now]].insert(*j);
      bel[x] = bel[now];
    }
    if (temp[x]) {
      int k = temp[x];
      vector<int> bc;
      for (auto j = ss[bel[now]].begin(); j != ss[bel[now]].end(); j++)
        bc.push_back(*j);
      for (int z = val[k] - 1; z < bc.size(); z++)
        ans[k] = min(ans[k], bc[z] - bc[z - val[k] + 1]);
      if (ans[k] != INF) ans[k] += L[k];
    }
  }
} AC;
int main() {
  scanf("%s", &ax);
  int n;
  scanf("%d", &n);
  memset(ans, INF, sizeof(ans));
  for (int i = 1; i <= n; i++) {
    scanf("%d%s", &val[i], &bx);
    id[i] = AC.Insert(bx, val[i]);
    temp[id[i]] = i;
    L[i] = strlen(bx);
  }
  AC.build();
  AC.buildTree();
  AC.make(ax);
  AC.calc(0);
  for (int i = 1; i <= n; i++) {
    if (ans[i] == INF)
      printf("%d\n", -1);
    else
      printf("%d\n", ans[i]);
  }
  return 0;
}
