#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
template <class T, class T2>
inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
template <class T>
inline void sortl(T &a) {
  sort(a.begin(), a.end());
}
template <class T>
inline void sortg(T &a) {
  sort(a.begin(), a.end(), greater<int>());
}
template <class T, class T2>
inline istream &operator>>(istream &is, pair<T, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class T2>
inline ostream &operator<<(ostream &os, const pair<T, T2> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v) {
  for (auto &curr : v) is >> curr;
  return is;
}
template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto curr : v) os << curr << ' ';
  return os;
}
template <class T, class T2>
inline ostream &operator<<(ostream &os, const map<T, T2> &m) {
  auto id = m.begin();
  while (id != m.end()) os << (*id).first << ' ' << (*(id++)).second;
  return os;
}
template <class T, class T2>
inline ostream &operator<<(ostream &os, const unordered_map<T, T2> &um) {
  auto id = um.begin();
  while (id != um.end()) os << (*id).first << ' ' << (*(id++)).second;
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const list<T> &l) {
  auto id = l.begin();
  while (id != l.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const set<T> &second) {
  auto id = second.begin();
  while (id != second.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const unordered_set<T> &us) {
  auto id = us.begin();
  while (id != us.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const multiset<T> &ms) {
  auto id = ms.begin();
  while (id != ms.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const unordered_multiset<T> &mus) {
  auto id = mus.begin();
  while (id != mus.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline void inArray(T a[], const int &n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <class T>
inline void outArray(T a[], const int &n) {
  for (int i = 0; i < n; i++) cout << a[i] << ' ';
}
const bool hasTests = 0;
struct node {
  int par, link;
  int key;
  vector<int> ch, go;
  vector<int> eow;
  node(int par, int key) : par(par), key(key) {
    link = 0;
    ch.resize(26, 0);
  };
};
vector<node> tr;
vector<queue<int>> app;
vector<int> need, sz;
vector<int> ans;
string second;
int n;
void addString(string &second, int k) {
  int curr = 0;
  for (char ch : second) {
    int c = ch - 'a';
    if (!tr[curr].ch[c]) {
      tr[curr].ch[c] = ((int)tr.size());
      tr[curr].go.push_back(((int)tr.size()));
      tr.emplace_back(curr, c);
    }
    curr = tr[curr].ch[c];
  }
  tr[curr].eow.push_back(k);
}
void input() {
  cin >> second >> n;
  app.resize(n);
  need.resize(n);
  sz.resize(n);
  ans.resize(n, ((int)second.size()) + 1);
  tr.emplace_back(0, -1);
  string temps;
  for (int i = 0; i < n; i++) {
    cin >> need[i] >> temps;
    sz[i] = ((int)temps.size());
    addString(temps, i);
  }
}
void output() {
  for (int i = 0; i < n; i++) {
    if (ans[i] == ((int)second.size()) + 1) {
      cout << "-1\n";
    } else {
      cout << ans[i] + sz[i] << '\n';
    }
  }
}
void findLink(int u) {
  if (tr[u].par == 0) {
    return;
  }
  int p = tr[tr[u].par].link;
  int c = tr[u].key;
  while (p && !tr[p].ch[c]) {
    p = tr[p].link;
  }
  tr[u].link = tr[p].ch[c];
}
void findEndingWords(int u) {
  int v = tr[u].link;
  for (auto w : tr[v].eow) {
    tr[u].eow.push_back(w);
  }
}
void pushLinks() {
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    findLink(u);
    findEndingWords(u);
    for (auto v : tr[u].go) {
      q.push(v);
    }
  }
}
void endingIn(int w, int pos) {
  app[w].push(pos);
  if (app[w].size() > need[w]) {
    app[w].pop();
  }
  if (app[w].size() == need[w]) {
    chkmin(ans[w], pos - app[w].front());
  }
}
void solve() {
  pushLinks();
  int p = 0;
  for (int i = 0; i < ((int)second.size()); i++) {
    int c = second[i] - 'a';
    while (p && !tr[p].ch[c]) {
      p = tr[p].link;
    }
    p = tr[p].ch[c];
    for (auto w : tr[p].eow) {
      endingIn(w, i);
    }
  }
}
void start() {
  int t = 1;
  if (hasTests) cin >> t;
  for (int i = 1; i <= t; i++) {
    input();
    solve();
    output();
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  start();
  return 0;
}
