#include <bits/stdc++.h>
using namespace std;
struct vertex {
  map<char, int> next, go;
  int p, link, leafLink;
  char pch;
  vector<int> leaf;
  vertex(int p = -1, char pch = -1) : p(p), pch(pch), link(-1), leafLink(-1) {}
};
vector<vertex> t;
void aho_init() {
  t.clear();
  t.push_back(vertex());
}
void add_string(string s, int id) {
  int v = 0;
  for (char c : s) {
    if (!t[v].next.count(c)) {
      t[v].next[c] = t.size();
      t.push_back(vertex(v, c));
    }
    v = t[v].next[c];
  }
  t[v].leaf.push_back(id);
}
int go(int v, char c);
int get_link(int v) {
  if (t[v].link < 0)
    if (!v || !t[v].p)
      t[v].link = 0;
    else
      t[v].link = go(get_link(t[v].p), t[v].pch);
  return t[v].link;
}
int get_leafLink(int v) {
  if (t[v].leafLink < 0) {
    if (!v || !t[v].p) {
      t[v].leafLink = 0;
    } else {
      if (t[get_link(v)].leaf.size() > 0) {
        t[v].leafLink = get_link(v);
      } else {
        t[v].leafLink = get_leafLink(get_link(v));
      }
    }
  }
  return t[v].leafLink;
}
int go(int v, char c) {
  if (!t[v].go.count(c))
    if (t[v].next.count(c))
      t[v].go[c] = t[v].next[c];
    else
      t[v].go[c] = v == 0 ? 0 : go(get_link(v), c);
  return t[v].go[c];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<pair<int, int> > queries;
  aho_init();
  for (int i = 0, colchin = n; i < colchin; ++i) {
    string m;
    int k;
    cin >> k >> m;
    queries.push_back(pair<int, int>(k, m.size()));
    add_string(m, i);
  }
  int curr = 0;
  vector<int> positions[n + 5];
  for (int i = 0, colchin = s.size(); i < colchin; ++i) {
    curr = go(curr, s[i]);
    int currLeaf = curr;
    while (currLeaf != 0) {
      for (int id : t[currLeaf].leaf) {
        positions[id].push_back(i);
      }
      currLeaf = get_leafLink(currLeaf);
    }
  }
  for (int i = 0, colchin = n; i < colchin; ++i) {
    if (positions[i].size() >= queries[i].first) {
      int k = queries[i].first;
      int minimum = 1e9;
      for (int j = 0, colchin = positions[i].size() - k + 1; j < colchin; ++j) {
        minimum = min(minimum, positions[i][j + k - 1] - positions[i][j]);
      }
      cout << minimum + queries[i].second << "\n";
    } else {
      cout << "-1\n";
    }
  }
  return 0;
}
