#include <algorithm>
#include <array>
#include <cassert>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int STRING_SZ = 200000;
typedef long long shash;
const int HASH1 = 3137;
long long hash1pows[STRING_SZ+1];
shash hashes[STRING_SZ+1];
string s;
void init() {
  hash1pows[0] = 1;
  for(int i = 1; i <= STRING_SZ; i++) hash1pows[i] = hash1pows[i-1] * HASH1;
}
inline long long getHash(int lhs, int rhs) {
  return hashes[rhs] - hashes[lhs] * hash1pows[rhs-lhs];
}
void genHash() {
  for(int i = 0; i < (int)s.size(); i++) {
    hashes[i+1] = hashes[i] * HASH1 + s[i];
  }
}

vector<pair<string, pair<int, int>>> queries[200005]; // string, <k, idx>
int ret[200005];
int main() {
  cin >> s;
  int q;
  cin >> q;
  for(int i = 0; i < q; i++) {
    string ss;
    int k;
    cin >> ss >> k;
    queries[ss.size()].emplace_back(ss, make_pair(--k, i));
  }
  memset(ret, -1, sizeof(ret));
  init();
  genHash();
  for(int a = 1; a <= (int)s.size(); a++) {
    if(queries[a].size() == 0) continue;
    int amt = 0;
    map<long long, vector<int>> dp;
    for(int b = a; b <= (int)s.size(); b++) {
      auto h = getHash(b - a, b);
      dp[h].push_back(b-a+1);
    }
    for(auto qry: queries[a]) {
      long long lhs = 0;
      for(auto ch: qry.first) {
        lhs *= HASH1; lhs += ch;
      }
      if(!dp.count(lhs)) continue;
      vector<int>& idx = dp[lhs];
      if(qry.second.first < (int)idx.size()) ret[qry.second.second] = idx[qry.second.first];
    }
  }
  for(int i = 0; i < q; i++) cout << ret[i] << "\n";
}