cin >> s + 1 >> m; n = strlen(s + 1); for (int i = 1; i <= n; ++i) B[ch(s[i])].set(i); while (m--) { int x, l; cin >> x >> c + 1; vector<int> vec; l = strlen(c + 1); ans.set(); int res = n + 1; for (int i = l; i; --i) ans &= B[ch(c[i])], i > 1 && (ans >>= 1, 0); for (int p = ans._Find_first(); p <= N; p = ans._Find_next(p)) vec.push_back(p); for (int i = 0; i + x - 1 < vec.size(); ++i) res = min(res, vec[i + x - 1] - vec[i] + 1 + l - 1); cout << (res > n ? -1 : res) << "\n"; } return0; }