#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cetak(T t) {
  cout << t << ')' << endl;
}
template <typename T, typename... V>
void cetak(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cerr << ", ";
  cetak(v...);
}
const int MOD = 1e9 + 7;
const int mx = 1e5 + 10;
string ss, k[mx];
int n, m[mx];
vector<int> isi[mx];
const int N = 1e5 + 5;
struct AhoCorasick {
  int trie[N][26];
  int fail[N];
  int saiz;
  int apa[N];
  AhoCorasick() {
    memset(trie[0], -1, sizeof trie[0]);
    saiz = 0;
  }
  void res() {
    for (int i = 0; i <= saiz; i++) {
      apa[i] = 0;
      for (int j = 0; j < 26; j++) {
        trie[i][j] = -1;
      }
    }
    saiz = 0;
  }
  void add(string str, int id) {
    int cur = 0;
    for (int i = 0; i < str.length(); i++) {
      int nex = str[i] - 'a';
      if (trie[cur][nex] == -1) {
        trie[cur][nex] = ++saiz;
        memset(trie[saiz], -1, sizeof trie[saiz]);
      }
      cur = trie[cur][nex];
    }
    apa[cur] = id;
  }
  void build() {
    queue<int> q;
    fail[0] = 0;
    for (int i = 0; i < 26; i++)
      if (trie[0][i] == -1)
        trie[0][i] = 0;
      else {
        int nex = trie[0][i];
        fail[nex] = 0;
        q.push(nex);
      }
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int i = 0; i < 26; i++)
        if (trie[now][i] == -1)
          trie[now][i] = trie[fail[now]][i];
        else {
          int nex = trie[now][i];
          fail[nex] = trie[fail[now]][i];
          q.push(nex);
        }
    }
  }
  int getIndex(string str) {
    int cur = 0;
    for (int i = 0; i < str.length(); i++) {
      cur = trie[cur][str[i] - 'a'];
    }
    return cur;
  }
};
AhoCorasick ini;
vector<int> occurance[mx];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> ss >> n;
  for (int i = 1; i <= n; i++)
    cin >> m[i] >> k[i], isi[(int)(k[i].size())].push_back(i);
  for (int i = 1; i <= (int)(ss.size()); i++) {
    if ((int)(isi[i].size()) == 0) continue;
    ini.res();
    for (int j : isi[i]) ini.add(k[j], j);
    ini.build();
    int cur = 0;
    for (int j = 0; j < (int)(ss.size()); j++) {
      cur = ini.trie[cur][ss[j] - 'a'];
      int x = ini.apa[cur];
      if (x == 0) continue;
      occurance[x].push_back(j);
    }
  }
  for (int i = 1; i <= n; i++) {
    if ((int)(occurance[i].size()) < m[i]) {
      cout << -1 << '\n';
      continue;
    }
    int jaw = 1e9;
    for (int l = 0; l < (int)(occurance[i].size()); l++) {
      int r = l + m[i] - 1;
      if (r >= (int)(occurance[i].size())) break;
      jaw = min(jaw, occurance[i][r] -
                         (occurance[i][l] - (int)(k[i].size()) + 1) + 1);
    }
    cout << jaw << '\n';
  }
}
