#include <bits/stdc++.h>
using namespace std;
const unsigned long long r = 997;
unsigned long long hsh[100100], kr[100100];
char s[100100], t[100100];
vector<pair<unsigned long long, pair<int, int> > > thsh[100100];
int main() {
  scanf("%s\n", s + 1);
  int len = strlen(s + 1);
  hsh[0] = 0;
  kr[0] = 1;
  for (int i = 1; i <= len; i++) {
    kr[i] = kr[i - 1] * r;
    hsh[i] = hsh[i - 1] * r + s[i];
  }
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d%s", &k, t);
    int l = strlen(t);
    unsigned long long x = 0;
    for (int j = 0; j < l; j++) x = x * r + t[j];
    thsh[l].push_back(make_pair(x, make_pair(k, i)));
  }
  int ans[100100];
  memset(ans, 0x3f, sizeof(ans));
  vector<vector<pair<unsigned long long, int> > > ord(1 << 20);
  for (int i = 0; i <= len; i++) {
    if (thsh[i].size() == 0) continue;
    vector<vector<int> > times(thsh[i].size());
    for (int j = 0; j < thsh[i].size(); j++)
      ord[thsh[i][j].first & 1048575].push_back(
          make_pair(thsh[i][j].first, j + 1));
    for (int j = i; j <= len; j++) {
      unsigned long long x = hsh[j] - hsh[j - i] * kr[i];
      if (ord[x & 1048575].size() == 0) continue;
      int ordx = -1;
      for (int w = 0; w < ord[x & 1048575].size(); w++)
        if (ord[x & 1048575][w].first == x) ordx = ord[x & 1048575][w].second;
      if (ordx < 0) continue;
      times[ordx - 1].push_back(j);
      if (times[ordx - 1].size() >= thsh[i][ordx - 1].second.first)
        ans[thsh[i][ordx - 1].second.second] = min(
            ans[thsh[i][ordx - 1].second.second],
            times[ordx - 1][times[ordx - 1].size() - 1] -
                times[ordx - 1]
                     [times[ordx - 1].size() - thsh[i][ordx - 1].second.first] +
                i);
    }
  }
  for (int i = 0; i < n; i++) printf("%d\n", ans[i] > 300000 ? -1 : ans[i]);
  return 0;
}
