#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000005;
const long long INFLL = 1000000000000000002ll;
const long long MOD = 1000000009;
inline long long min(long long a, long long b, long long c) {
  return min(min(a, b), c);
}
inline long long min(long long a, long long b, long long c, long long d) {
  return min(min(min(a, b), c), d);
}
inline long long max(long long a, long long b, long long c) {
  return max(max(a, b), c);
}
inline long long max(long long a, long long b, long long c, long long d) {
  return max(max(max(a, b), c), d);
}
int Ans[100005], K[100005], L[100005], Q;
string S;
vector<int> Pos[100005];
struct AhoCorasick {
  struct Node {
    bool dictionary_fail;
    vector<int> words;
    Node *next[26];
    Node *parent;
    Node *fail;
    Node() {
      for (int i = (0); i <= (25); i++) next[i] = NULL;
      dictionary_fail = false;
    }
  };
  Node *root;
  AhoCorasick() { root = new Node(); }
  void add(string s, int id) {
    Node *n = root;
    for (int i = (0); i <= (((int)s.size()) - 1); i++) {
      int l = s[i] - 'a';
      if (n->next[l] == NULL) {
        n->next[l] = new Node();
        n->next[l]->parent = n;
      }
      n = n->next[l];
    }
    n->words.push_back(id);
  }
  string getWord(Node *n) {
    string ret;
    while (n != root) {
      Node *p = n->parent;
      for (int l = (0); l <= (25); l++)
        if (p->next[l] == n) ret += (char)(l + 'a');
      n = n->parent;
    }
    reverse(ret.begin(), ret.end());
    return ret;
  }
  void printWords() {
    queue<Node *> q;
    q.push(root);
    while (!q.empty()) {
      Node *n = q.front();
      q.pop();
      if (!n->words.empty()) cout << getWord(n) << "\n";
      for (int l = (0); l <= (25); l++)
        if (n->next[l] != NULL) q.push(n->next[l]);
    }
  }
  void makeFail() {
    queue<Node *> q;
    root->fail = root;
    q.push(root);
    while (!q.empty()) {
      Node *n = q.front();
      q.pop();
      for (int l = (0); l <= (25); l++)
        if (n->next[l] != NULL) {
          Node *child = n->next[l];
          Node *suf = n->fail;
          while (suf->next[l] == NULL) {
            if (suf == root) break;
            suf = suf->fail;
          }
          if (suf->next[l] != NULL && suf->next[l] != child)
            child->fail = suf->next[l];
          else
            child->fail = suf;
          child->dictionary_fail =
              (!child->fail->words.empty()) | child->fail->dictionary_fail;
          q.push(n->next[l]);
        }
    }
  }
  vector<pair<int, int>> match(string t) {
    Node *n = root;
    vector<pair<int, int>> ret;
    for (int i = (0); i <= (((int)t.size()) - 1); i++) {
      int l = t[i] - 'a';
      while (n->next[l] == NULL) {
        if (n == root) break;
        n = n->fail;
      }
      if (n->next[l] != NULL) n = n->next[l];
      Node *suf = n;
      while (!suf->words.empty() || suf->dictionary_fail) {
        for (int id : suf->words) Pos[id].push_back(i);
        suf = suf->fail;
      }
    }
    return ret;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  AhoCorasick aho;
  cin >> S >> Q;
  for (int q = (1); q <= (Q); q++) {
    string t;
    cin >> K[q] >> t;
    L[q] = ((int)t.size());
    aho.add(t, q);
  }
  aho.makeFail();
  aho.match(S);
  for (int q = (1); q <= (Q); q++) {
    if (((int)Pos[q].size()) < K[q]) {
      cout << "-1\n";
      continue;
    }
    int ans = INF;
    for (int i = (K[q] - 1); i <= (((int)Pos[q].size()) - 1); i++)
      ans = min(ans, Pos[q][i] - Pos[q][i - K[q] + 1]);
    cout << ans + L[q] << "\n";
  }
}
