#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
long long int myRand(long long int R) {
  long long int val = rng() % R;
  assert(val >= 0);
  return val;
}
const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
const int32_t MOD = 1e9 + 7;
using namespace std;
void my_debugger(string second, long long int LINE_NUM) { cerr << '\n'; }
template <typename start, typename... end>
void my_debugger(string second, long long int LINE_NUM, start x, end... y) {
  if (second.back() != ',') {
    second += ',';
    cerr << "LINE(" << LINE_NUM << "): ";
  }
  long long int i = second.find(',');
  cerr << second.substr(0, i) << " = " << x;
  second = second.substr(i + 1);
  if (!second.empty()) cerr << ", ";
  my_debugger(second, LINE_NUM, y...);
}
struct aho_corasick {
  struct node {
    long long int nxt[26];
    long long int go[26];
    bool leaf;
    long long int p;
    long long int pch;
    long long int link;
    long long int good_link;
    long long int val;
    node() {
      fill(begin(nxt), end(nxt), -1);
      fill(begin(go), end(go), -1);
      leaf = false;
      p = pch = -1;
      link = good_link = -1;
      val = -1;
    }
  };
  vector<node> nodes;
  aho_corasick() { nodes = vector<node>(1, node()); }
  long long int add(const string& second) {
    long long int cur = 0;
    for (auto it : second) {
      long long int ch = it - 'a';
      if (nodes[cur].nxt[ch] == -1) {
        nodes[cur].nxt[ch] = nodes.size();
        nodes.emplace_back(node());
        nodes.back().p = cur;
        nodes.back().pch = ch;
      }
      cur = nodes[cur].nxt[ch];
    }
    nodes[cur].leaf = true;
    return cur;
  }
  long long int suf_link(long long int v) {
    if (nodes[v].link == -1) {
      if (v == 0 || nodes[v].p == 0)
        nodes[v].link = 0;
      else
        nodes[v].link = go(suf_link(nodes[v].p), nodes[v].pch);
    }
    return nodes[v].link;
  }
  long long int go(long long int v, long long int ch) {
    if (nodes[v].go[ch] == -1) {
      if (nodes[v].nxt[ch] != -1)
        nodes[v].go[ch] = nodes[v].nxt[ch];
      else
        nodes[v].go[ch] = (v == 0) ? 0 : go(suf_link(v), ch);
    }
    return nodes[v].go[ch];
  }
};
vector<tuple<long long int, string, long long int>> queries[100005];
vector<long long int> v[100005];
long long int ans[100005];
long long int need[100005];
long long int slen[100005];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  long long int tests = 1;
  for (long long int ii = 0; ii < (long long int)tests; ii++) {
    string second;
    cin >> second;
    long long int q;
    cin >> q;
    for (long long int i = 0; i < (long long int)q; i++) {
      ans[i] = -1;
      long long int k;
      string s1;
      cin >> k >> s1;
      need[i] = k;
      slen[i] = s1.size();
      long long int siz = s1.size();
      queries[siz].push_back({k, s1, i});
    }
    long long int len = second.size();
    for (long long int i = 0; i < (long long int)len + 1; i++) {
      if (queries[i].empty()) continue;
      vector<long long int> indices;
      aho_corasick aho;
      for (auto& it : queries[i]) {
        long long int ind;
        string s1;
        tie(ignore, s1, ind) = it;
        indices.push_back(ind);
        long long int v = aho.add(s1);
        aho.nodes[v].val = ind;
      }
      long long int cur = 0;
      long long int j = 0;
      for (auto& it : second) {
        long long int ch = it - 'a';
        cur = aho.go(cur, ch);
        if (aho.nodes[cur].leaf) {
          long long int ind = aho.nodes[cur].val;
          long long int siz = slen[ind];
          v[ind].push_back(j - siz + 1);
        }
        j++;
      }
      for (auto& ind : indices) {
        long long int siz = v[ind].size();
        for (long long int j = 0; j < siz; j++) {
          if (j + need[ind] - 1 >= siz) break;
          long long int l = v[ind][j];
          long long int r = v[ind][j + need[ind] - 1];
          r = r + slen[ind] - 1;
          if (ans[ind] == -1 || ans[ind] > r - l + 1) ans[ind] = r - l + 1;
        }
      }
    }
    for (long long int i = 0; i < (long long int)q; i++) cout << ans[i] << '\n';
  }
  return 0;
}
