#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 450;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && str[i] != str[j]) j = nxt[j];
		nxt[++i] = ++j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 400;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 210;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {998244353, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 180;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1ULL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1ULL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 450;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 200;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 270;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

const int N = 100010;
char s[N], str[N];
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 250;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && str[i] != str[j]) j = nxt[j];
		nxt[++i] = ++j;
	}
}

int main()
{
	scanf("%s", s);
	int n = strlen(s);
    for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	int m;
	scanf("%d", &m);
	while (m--) {
		int t;
		scanf("%d%s", &t, str);
		int l = strlen(str);
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				printf("-1\n");
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				printf("-1\n");
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			printf("%d\n", ans);
		} else {
		    vector<int> pos;
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 650;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;

map<pair<int, int>, int > mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 800;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		mp[make_pair(x, y)] = 1;
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			if (!mp.count(make_pair(x, y))) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i < sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;

unordered_set<unsigned long long> mp;
const int N = 100010;
char s[N], sss[N];
int o[N];
string ss[N], str;
struct point {
	int x, y;
	int id;
	friend bool operator < (const point &p, const point &q) {
		if (p.x != q.x) return p.x < q.x;
		if (p.y != q.y) return p.y < q.y;
		return p.id < q.id;
	}

	point() {}
	point (int x, int y, int id):x(x), y(y), id(id) {}
};
vector<point> lengths[N];

const int keys[2] = {137, 10007};
const int mods[2] = {1000000009, 998244353};
const int sz = 380;
int nxt[N];

void get_next(int n) {
    int i, j;
	j = nxt[0] = -1;
	i = 0;
	while (i < n) {
		while (j != -1 && sss[i] != sss[j]) j = nxt[j];
	    nxt[++i] = ++j;
		// if (sss[++i] == sss[++j]) nxt[i] = nxt[j];
		// else nxt[i] = j;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	int n = strlen(s);
    int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> o[i] >> ss[i];

		int x = 0, y = 0;
		if (ss[i].length() > sz) continue;
		for (int j = 0; j < ss[i].length(); j++) {
		    x = (1LL * x * keys[0] + ss[i][j]) % mods[0];
			y = (1LL * y * keys[1] + ss[i][j]) % mods[1];
		}

		unsigned long long tmp = x * (1LL << 31) + y;
	    mp.insert(tmp);
	}

	for (int i = 0; i < n; i++) {
		int x = 0, y = 0;
	    for (int j = 0; j + i < n && j < sz; j++) {
		    x = (1LL * x * keys[0] + s[i + j]) % mods[0];
			y = (1LL * y * keys[1] + s[i + j]) % mods[1];
			unsigned long long tmp = x * (1LL << 31) + y;
			if (!mp.count(tmp)) continue;
			lengths[j + 1].push_back(point(x, y, i));
		}
	}

	for (int i = 0; i <= sz; i++) {
		sort(lengths[i].begin(), lengths[i].end());
	}

	for (int k = 1; k <= m; k++) {
		str = ss[k];
		int t = o[k];
		int l = str.length();
		if (l <= sz) {
		    int x = 0, y = 0;
			for (int i = 0; i < l; i++) {
		        x = (1LL * x * keys[0] + str[i]) % mods[0];
			    y = (1LL * y * keys[1] + str[i]) % mods[1];
			}

			if (lengths[l].size() < t) {
				cout << -1 << endl;
				continue;
			}

			int lt = 0, rt = lengths[l].size() - 1, mid, pos = -1;
			while (lt <= rt) {
				mid = (lt + rt) >> 1;
				if (lengths[l][mid].x > x || (lengths[l][mid].x == x && lengths[l][mid].y >= y)) {
					pos = mid;
					rt = mid - 1;
				} else lt = mid + 1;
			}

			if (pos == -1) {
				cout << -1 << endl;
				continue;
			}

			if (lengths[l][pos].x != x || lengths[l][pos].y != y) {
				break;
			}

			int ans = -1;
			for (int i = pos + t - 1; i < lengths[l].size(); i++) {
				if (lengths[l][i].x != x || lengths[l][i].y != y) {
					break;
				}
				int st = lengths[l][i - t + 1].id - l + 1;
				int tmp = lengths[l][i].id - st + 1;
				if (ans == -1 || tmp < ans) ans = tmp;
			}

			cout << ans << endl;
		} else {
		    vector<int> pos;
			strcpy(sss, str.c_str());
			get_next(l);
			int i = 0, j = 0;
			while (i < n) {
		        while (-1 != j && s[i] != str[j]) {
				    j = nxt[j];
			    }
			    i++, j++;
			    if (j >= l) {
				    pos.push_back(i - 1);
				    j = nxt[j];
			    }
			}

			int ans = -1;
			for (i = t - 1; i < pos.size(); i++) {
				int st = pos[i - t + 1] - l + 1;
				int tmp = pos[i] - st + 1;
				if (ans == -1 || ans > tmp) ans = tmp;
			}
		    cout << ans << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 121;

string text;
char buffer[N];

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        scanf("%d %s", &k, buffer);
        str = buffer;
    }

    LL calc() {
        LL hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }

        return hash;
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

} patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
LL power[N];

void prepare_magic() {
    power[0] = 1;
    for (int i = 1; i < N; i ++) {
        power[i] = power[i-1] * MAGIC;
    }
    for (int i = 0; i < int(text.length()); i ++) {
        Hash[i+1] = Hash[i] * MAGIC + text[i];
    }
}

void prepare_text(int interval) {
    seq.clear();
    for (int i = interval - 1; i < int(text.size()); i ++) {
        LL hash_v = Hash[i+1] - Hash[i + 1 - interval]*power[interval];
        seq[hash_v].push_back(i);
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    scanf("%s%d", buffer, &m);
    text = buffer;
    prepare_magic();
    rep(i, m) {
        patterns[i].read(i);
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        prepare_text(patterns[i].size());
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }
        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].calc();
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = k - 1; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - (vec[z+1-k]-patterns[o].size()));
                    }
                }
                answer[patterns[o].id] = minMal;
            }
        }
    }

    rep(i, m) {
        printf("%d\n", answer[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 17;

string text;

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        cin >> k >> str;
    }

    LL calc() {
        LL hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }

        return hash;
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

}patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
void prepare_text(int interval) {
    seq.clear();
    LL delta = 1;
    rep(i, interval) {
        delta *= MAGIC;
    }
    for (int i = 0; i < int(text.size()); i ++) {
        Hash[i+1] = Hash[i]*MAGIC + text[i];
        if (i + 1 >= interval) {
            LL hash_v = Hash[i+1] - Hash[i + 1 - interval]*delta;
            seq[hash_v].push_back(i);
        }
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    cin >> text;
    cin >> m;
    rep(i, m) {
        patterns[i].read(i);
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        prepare_text(patterns[i].size());
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }
        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].calc();
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = 0; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - (vec[z+1-k]-patterns[o].size()));
                    }
                }
                answer[patterns[o].id] = minMal;
            }
        }
    }

    rep(i, m) {
        cout << answer[i] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 121;

string text;
char buffer[N];

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        scanf("%d %s", &k, buffer);
        str = buffer;
    }

    void calc() {
        hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

} patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
LL power[N];

void prepare_magic() {
    power[0] = 1;
    for (int i = 1; i < N; i ++) {
        power[i] = power[i-1] * MAGIC;
    }
    for (int i = 0; i < int(text.length()); i ++) {
        Hash[i+1] = Hash[i] * MAGIC + text[i];
    }
}

void prepare_text(int interval) {
    for (int i = interval - 1; i < int(text.size()); i ++) {
        LL hash_v = Hash[i+1] - Hash[i+1 - interval]*power[interval];
        seq[hash_v].emplace_back(i);
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    scanf("%s%d", buffer, &m);
    text = buffer;
    prepare_magic();
    rep(i, m) {
        patterns[i].read(i);
        patterns[i].calc();
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }

        {
            seq.clear();
            for (int o = i; o < j; o ++) {
                LL hash_v = patterns[o].hash;
                seq[hash_v] = vector<int>();
            }
            prepare_text(patterns[i].size());
        }

        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].hash;
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = k - 1; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - vec[z+1-k]);
                    }
                }
                answer[patterns[o].id] = minMal + patterns[o].size();
            }
        }
    }

    rep(i, m) {
        printf("%d\n", answer[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 121;

string text;
char buffer[N];

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        scanf("%d %s", &k, buffer);
        str = buffer;
    }

    LL calc() {
        LL hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }

        return hash;
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

}patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
void prepare_text(int interval) {
    seq.clear();
    LL delta = 1;
    rep(i, interval) {
        delta *= MAGIC;
    }
    for (int i = 0; i < int(text.size()); i ++) {
        Hash[i+1] = Hash[i]*MAGIC + text[i];
        if (i + 1 >= interval) {
            LL hash_v = Hash[i+1] - Hash[i + 1 - interval]*delta;
            seq[hash_v].push_back(i);
        }
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    scanf("%s%d", buffer, &m);
    text = buffer;
    rep(i, m) {
        patterns[i].read(i);
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        prepare_text(patterns[i].size());
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }
        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].calc();
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = k - 1; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - (vec[z+1-k]-patterns[o].size()));
                    }
                }
                answer[patterns[o].id] = minMal;
            }
        }
    }

    rep(i, m) {
        printf("%d\n", answer[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 79;

string text;

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        cin >> k >> str;
    }

    LL calc() {
        LL hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }

        return hash;
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

}patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
void prepare_text(int interval) {
    seq.clear();
    LL delta = 1;
    rep(i, interval) {
        delta *= MAGIC;
    }
    for (int i = 0; i < int(text.size()); i ++) {
        Hash[i+1] = Hash[i]*MAGIC + text[i];
        if (i + 1 >= interval) {
            LL hash_v = Hash[i+1] - Hash[i + 1 - interval]*delta;
            seq[hash_v].push_back(i);
        }
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    cin >> text;
    cin >> m;
    rep(i, m) {
        patterns[i].read(i);
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        prepare_text(patterns[i].size());
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }
        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].calc();
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = 0; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - (vec[z+1-k]-patterns[o].size()));
                    }
                }
                answer[patterns[o].id] = minMal;
            }
        }
    }

    rep(i, m) {
        cout << answer[i] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 121;

string text;
char buffer[N];

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        scanf("%d %s", &k, buffer);
        str = buffer;
    }

    LL calc() {
        LL hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }

        return hash;
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

}patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
void prepare_text(int interval) {
    seq.clear();
    LL delta = 1;
    rep(i, interval) {
        delta *= MAGIC;
    }
    for (int i = 0; i < int(text.size()); i ++) {
        Hash[i+1] = Hash[i]*MAGIC + text[i];
        if (i + 1 >= interval) {
            LL hash_v = Hash[i+1] - Hash[i + 1 - interval]*delta;
            seq[hash_v].push_back(i);
        }
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    scanf("%s%d", buffer, &m);
    text = buffer;
    rep(i, m) {
        patterns[i].read(i);
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        prepare_text(patterns[i].size());
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }
        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].calc();
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = 0; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - (vec[z+1-k]-patterns[o].size()));
                    }
                }
                answer[patterns[o].id] = minMal;
            }
        }
    }

    rep(i, m) {
        printf("%d\n", answer[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 79;

string text;
char buffer[N];

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        scanf("%d %s", &k, buffer);
        str = buffer;
    }

    LL calc() {
        LL hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }

        return hash;
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

}patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
void prepare_text(int interval) {
    seq.clear();
    LL delta = 1;
    rep(i, interval) {
        delta *= MAGIC;
    }
    for (int i = 0; i < int(text.size()); i ++) {
        Hash[i+1] = Hash[i]*MAGIC + text[i];
        if (i + 1 >= interval) {
            LL hash_v = Hash[i+1] - Hash[i + 1 - interval]*delta;
            seq[hash_v].push_back(i);
        }
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    scanf("%s%d", buffer, &m);
    text = buffer;
    rep(i, m) {
        patterns[i].read(i);
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        prepare_text(patterns[i].size());
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }
        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].calc();
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = 0; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - (vec[z+1-k]-patterns[o].size()));
                    }
                }
                answer[patterns[o].id] = minMal;
            }
        }
    }

    rep(i, m) {
        printf("%d\n", answer[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long LL;
using namespace std;
#define ALL(x) (x.begin(), x.end())
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 1e5 + 5;
const int MAGIC = 121;

string text;
char buffer[N];

struct Pattern {
    string str;
    int k, id;
    LL hash;

    void read(int _id) {
        id = _id;
        scanf("%d %s", &k, buffer);
        str = buffer;
    }

    void calc() {
        hash = 0;
        for (const char &ch: str) {
            hash = hash * MAGIC + ch;
        }
    }

    int size() {
        return str.length();
    }

    bool operator<(const Pattern &rhs) const {
        return str.length() < rhs.str.length();
    }

} patterns[N];

unordered_map<LL, vector<int>> seq;
LL Hash[N];
LL power[N];

void prepare_magic() {
    power[0] = 1;
    for (int i = 1; i < N; i ++) {
        power[i] = power[i-1] * MAGIC;
    }
    for (int i = 0; i < int(text.length()); i ++) {
        Hash[i+1] = Hash[i] * MAGIC + text[i];
    }
}

void prepare_text(int interval) {
    for (int i = interval - 1; i < int(text.size()); i ++) {
        LL hash_v = Hash[i+1] - Hash[i+1 - interval]*power[interval];
        if (seq.count(hash_v)) {
            seq[hash_v].emplace_back(i);
        }
    }
}

int answer[N];

int main() {
    ios :: sync_with_stdio(false);
    cout << fixed << setprecision(16);
    int m;
    scanf("%s%d", buffer, &m);
    text = buffer;
    prepare_magic();
    rep(i, m) {
        patterns[i].read(i);
        patterns[i].calc();
    }
    sort(patterns, patterns + m);
    rep(i, m) {
        answer[i] = -1;
    }
    for (int i = 0, j; i < m; i = j) {
        j = i + 1;
        while(j < m && !(patterns[j-1] < patterns[j])) {
            j ++;
        }

        {
            seq.clear();
            for (int o = i; o < j; o ++) {
                LL hash_v = patterns[o].hash;
                seq[hash_v] = vector<int>();
            }
            prepare_text(patterns[i].size());
        }

        for (int o = i; o < j; o ++) {
            LL hash_v = patterns[o].hash;
            int k = patterns[o].k;
            if (int(seq[hash_v].size()) >= k) {
                vector<int> &vec = seq[hash_v];
                int minMal = N;
                for (int z = k - 1; z < int(vec.size()); z ++) {
                    if (z + 1 >= k) {
                        minMal = min(minMal, vec[z] - vec[z+1-k]);
                    }
                }
                answer[patterns[o].id] = minMal + patterns[o].size();
            }
        }
    }

    rep(i, m) {
        printf("%d\n", answer[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 7;

inline int R()
{
	int rt = 0;
	char ch = getchar();
	bool isn = false;
	for ( ; ch < '0' || ch > '9'; ch = getchar() )
		isn = ch == '-' ? true : isn;
	for ( ; ch >= '0' && ch <= '9'; ch = getchar() )
		rt = rt * 10 + ch - '0';
	return isn ? -rt : rt;
}

struct Node
{
	int s[27];
	int id, ql, len;
	vector<int> oc;
	int fail;
}t[MAXN];
int nu;

char c[MAXN];
void Insert ( int ni )
{
	int nf = 0, tq = R();
	scanf ( "%s", c + 1 );
	int len = strlen ( c + 1 );
	for ( int i = 1; i <= len; ++i )
	{
		int nc = c[i] - 'a';
		if ( !t[nf].s[nc] )
			t[nf].s[nc] = ++nu;
		nf = t[nf].s[nc];
	}
	t[nf].id = ni, t[nf].ql = tq, t[nf].len = len;
}

int que[MAXN];
void Build ()
{
	int head = 0, tail = 1;
	for ( int i = 0; i < 26; ++i )
		if ( t[0].s[i] )
			que[++head] = t[0].s[i];
	while ( head >= tail )
	{
		int nf = que[tail++];
		for ( int i = 0; i < 26; ++i )
			if ( t[nf].s[i] )
			{
				int ff = t[nf].fail;
				while ( ff && !t[ff].s[i] )
					ff = t[ff].fail;
				t[t[nf].s[i]].fail = t[ff].s[i];
				que[++head] = t[nf].s[i];
			}
	}
}

void Fnd ( int nf, int np )
{
	while ( nf )
	{
		if ( t[nf].id )
			t[nf].oc.push_back ( np );
		nf = t[nf].fail;
	}
}

char s[MAXN];
void Query ()
{
	int nf = 0;
	int len = strlen ( s + 1 );
	for ( int i = 1; i <= len; ++i )
	{
		int nc = s[i] - 'a';
		while ( nf && !t[nf].s[nc] )
			nf = t[nf].fail;
		nf = t[nf].s[nc];
		Fnd ( nf, i );
	}
}

int ans[MAXN];
int main()
{
//	freopen ( "test.in", "r", stdin );
	scanf ( "%s", s + 1 );
	int q = R();
	for ( int i = 1; i <= q; ++i )
		Insert ( i );
	Build();
	Query();
	for ( int i = 1; i <= nu; ++i )
	{
		if ( t[i].id )
		{
			int nl = 0, nr = t[i].ql - 1, nans = 2e9;
			while ( nr < t[i].oc.size() )
			{
				nans = min ( nans, t[i].oc[nr] - t[i].oc[nl] + t[i].len );
				++nl, ++nr;
			}
			ans[t[i].id] = nans == 2e9 ? -1 : nans;
		}
	}
	for ( int i = 1; i <= q; ++i )
		printf ( "%d\n", ans[i] );
	return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>

using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 7;

inline int R()
{
	int rt = 0;
	char ch = getchar();
	bool isn = false;
	for ( ; ch < '0' || ch > '9'; ch = getchar() )
		isn = ch == '-' ? true : isn;
	for ( ; ch >= '0' && ch <= '9'; ch = getchar() )
		rt = rt * 10 + ch - '0';
	return isn ? -rt : rt;
}

struct Node
{
	int s[27];
	int id, ql, len;
	vector<int> oc;
	int fail, vap;
}t[MAXN];
int nu;

char c[MAXN];
void Insert ( int ni )
{
	int nf = 0, tq = R();
	scanf ( "%s", c + 1 );
	int len = strlen ( c + 1 );
	for ( int i = 1; i <= len; ++i )
	{
		int nc = c[i] - 'a';
		if ( !t[nf].s[nc] )
			t[nf].s[nc] = ++nu;
		nf = t[nf].s[nc];
	}
	t[nf].id = ni, t[nf].ql = tq, t[nf].len = len;
}

int que[MAXN];
void Build ()
{
	int head = 0, tail = 1;
	for ( int i = 0; i < 26; ++i )
		if ( t[0].s[i] )
			que[++head] = t[0].s[i];
	while ( head >= tail )
	{
		int nf = que[tail++];
		for ( int i = 0; i < 26; ++i )
			if ( t[nf].s[i] )
			{
				int ff = t[nf].fail;
				while ( ff && !t[ff].s[i] )
					ff = t[ff].fail;
				t[t[nf].s[i]].fail = t[ff].s[i];
				if ( t[t[ff].s[i]].id )
					t[t[nf].s[i]].vap = t[ff].s[i];
				else
					t[t[nf].s[i]].vap = t[t[ff].s[i]].vap;
				que[++head] = t[nf].s[i];
			}
	}
}

void Fnd ( int nf, int np )
{
	while ( nf )
	{
		if ( t[nf].id )
			t[nf].oc.push_back ( np );
		nf = t[nf].vap;
	}
}

char s[MAXN];
void Query ()
{
	int nf = 0;
	int len = strlen ( s + 1 );
	for ( int i = 1; i <= len; ++i )
	{
		int nc = s[i] - 'a';
		while ( nf && !t[nf].s[nc] )
			nf = t[nf].fail;
		nf = t[nf].s[nc];
		Fnd ( nf, i );
	}
}

int ans[MAXN];
int main()
{
//	freopen ( "test.in", "r", stdin );
	scanf ( "%s", s + 1 );
	int q = R();
	for ( int i = 1; i <= q; ++i )
		Insert ( i );
	Build();
	Query();
	for ( int i = 1; i <= nu; ++i )
	{
		if ( t[i].id )
		{
			int nl = 0, nr = t[i].ql - 1, nans = 2e9;
			while ( nr < t[i].oc.size() )
			{
				nans = min ( nans, t[i].oc[nr] - t[i].oc[nl] + t[i].len );
				++nl, ++nr;
			}
			ans[t[i].id] = nans == 2e9 ? -1 : nans;
		}
	}
	for ( int i = 1; i <= q; ++i )
		printf ( "%d\n", ans[i] );
	return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>

using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 7;

inline int R()
{
	int rt = 0;
	char ch = getchar();
	bool isn = false;
	for ( ; ch < '0' || ch > '9'; ch = getchar() )
		isn = ch == '-' ? true : isn;
	for ( ; ch >= '0' && ch <= '9'; ch = getchar() )
		rt = rt * 10 + ch - '0';
	return isn ? -rt : rt;
}

struct Node
{
	int s[27];
	int id, ql, len;
	vector<int> oc;
	int fail;
}t[MAXN];
int nu;

char c[MAXN];
void Insert ( int ni )
{
	int nf = 0, tq = R();
	scanf ( "%s", c + 1 );
	int len = strlen ( c + 1 );
	for ( int i = 1; i <= len; ++i )
	{
		int nc = c[i] - 'a';
		if ( !t[nf].s[nc] )
			t[nf].s[nc] = ++nu;
		nf = t[nf].s[nc];
	}
	t[nf].id = ni, t[nf].ql = tq, t[nf].len = len;
}

int que[MAXN];
void Build ()
{
	int head = 0, tail = 1;
	for ( int i = 0; i < 26; ++i )
		if ( t[0].s[i] )
			que[++head] = t[0].s[i];
	while ( head >= tail )
	{
		int nf = que[tail++];
		for ( int i = 0; i < 26; ++i )
			if ( t[nf].s[i] )
			{
				int ff = t[nf].fail;
				while ( ff && !t[ff].s[i] )
					ff = t[ff].fail;
				t[t[nf].s[i]].fail = t[ff].s[i];
				que[++head] = t[nf].s[i];
			}
	}
}

void Fnd ( int nf, int np )
{
	while ( nf )
	{
		if ( t[nf].id )
			t[nf].oc.push_back ( np );
		nf = t[nf].fail;
	}
}

char s[MAXN];
void Query ()
{
	int nf = 0;
	int len = strlen ( s + 1 );
	for ( int i = 1; i <= len; ++i )
	{
		int nc = s[i] - 'a';
		while ( nf && !t[nf].s[nc] )
			nf = t[nf].fail;
		nf = t[nf].s[nc];
		Fnd ( nf, i );
	}
}

int ans[MAXN];
int main()
{
//	freopen ( "test.in", "r", stdin );
	scanf ( "%s", s + 1 );
	int q = R();
	for ( int i = 1; i <= q; ++i )
		Insert ( i );
	Build();
	Query();
	for ( int i = 1; i <= nu; ++i )
	{
		if ( t[i].id )
		{
			int nl = 0, nr = t[i].ql - 1, nans = 2e9;
			while ( nr < t[i].oc.size() )
			{
				nans = min ( nans, t[i].oc[nr] - t[i].oc[nl] + t[i].len );
				++nl, ++nr;
			}
			ans[t[i].id] = nans == 2e9 ? -1 : nans;
		}
	}
	for ( int i = 1; i <= q; ++i )
		printf ( "%d\n", ans[i] );
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
using namespace std;
const int MAXN=110000;
const int MAXS=26;
const int INF=1E9;
vector<int> righ[MAXN];
struct ACAutomaton
{
	struct Node
	{
		int nxt[MAXS], fail;
		vector<int> pos;
	} st[MAXN];
	int cnt, root;
	int que[MAXN];
	void init()
	{
		cnt=0; root=++cnt;
	}
	void insert(char* s, int d)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			int x=s[i]-'a';
			if (!st[p].nxt[x]) st[p].nxt[x]=++cnt;
			p=st[p].nxt[x];
		}
		st[p].pos.push_back(d);
	}
	void build()
	{
		int op=0, cl=0;
		que[cl++]=root;
		while (op<cl)
		{
			int p=que[op++];
			for (int i=0; i<MAXS; i++)
			{
				int q=st[p].nxt[i], t=st[p].fail;
				t=t?st[t].nxt[i]:root;
				if (q) st[q].fail=t, que[cl++]=q;
				else st[p].nxt[i]=t;
			}
		}
		for (int i=2; i<=cnt; i++)
		{
			assert(st[i].fail<i);
			for (int t:st[st[i].fail].pos)
				st[i].pos.push_back(t);
		}
	}
	void query(char* s)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			p=st[p].nxt[s[i]-'a'];
			for (int t:st[p].pos)
				righ[t].push_back(i);
		}
	}
} acam;
char s[MAXN], t[MAXN];
int c[MAXN], l[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int n;
	scanf("%s%d", s, &n);
	acam.init();
	for (int i=1; i<=n; i++)
	{
		scanf("%d%s", &c[i], t);
		l[i]=strlen(t);
		acam.insert(t, i);
	}
	acam.build();
	acam.query(s);
	for (int i=1; i<=n; i++)
	{
		int ans=INF;
		for (int j=0; j+c[i]-1<righ[i].size(); j++)
			ans=min(ans, righ[i][j+c[i]-1]-righ[i][j]);
		printf("%d\n", ans==INF?-1:ans+l[i]);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN=110000;
const int MAXS=26;
const int INF=1E9;
vector<int> righ[MAXN];
struct ACAutomaton
{
	struct Node
	{
		int nxt[MAXS], fail;
		vector<int> pos;
	} st[MAXN];
	int cnt, root;
	int que[MAXN];
	void init()
	{
		cnt=0; root=++cnt;
	}
	void insert(char* s, int d)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			int x=s[i]-'a';
			if (!st[p].nxt[x]) st[p].nxt[x]=++cnt;
			p=st[p].nxt[x];
		}
		st[p].pos.push_back(d);
	}
	void build()
	{
		int op=0, cl=0;
		que[cl++]=root;
		while (op<cl)
		{
			int p=que[op++];
			for (int i=0; i<MAXS; i++)
			{
				int q=st[p].nxt[i], t=st[p].fail;
				t=t?st[t].nxt[i]:root;
				if (q)
				{
					st[q].fail=t, que[cl++]=q;
					for (int x:st[st[p].fail].pos)
						st[p].pos.push_back(x);
				}
				else st[p].nxt[i]=t;
			}
		}
	}
	void query(char* s)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			p=st[p].nxt[s[i]-'a'];
			for (int t:st[p].pos)
				righ[t].push_back(i);
		}
	}
} acam;
char s[MAXN], t[MAXN];
int c[MAXN], l[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int n;
	scanf("%s%d", s, &n);
	acam.init();
	for (int i=1; i<=n; i++)
	{
		scanf("%d%s", &c[i], t);
		l[i]=strlen(t);
		acam.insert(t, i);
	}
	acam.build();
	acam.query(s);
	for (int i=1; i<=n; i++)
	{
		int ans=INF;
		for (int j=0; j+c[i]-1<righ[i].size(); j++)
			ans=min(ans, righ[i][j+c[i]-1]-righ[i][j]);
		printf("%d\n", ans==INF?-1:ans+l[i]);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN=110000;
const int MAXS=26;
const int INF=1E9;
vector<int> righ[MAXN];
struct ACAutomaton
{
	struct Node
	{
		int nxt[MAXS], fail;
		vector<int> pos;
	} st[MAXN];
	int cnt, root;
	int que[MAXN];
	void init()
	{
		cnt=0; root=++cnt;
	}
	void insert(char* s, int d)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			int x=s[i]-'a';
			if (!st[p].nxt[x]) st[p].nxt[x]=++cnt;
			p=st[p].nxt[x];
		}
		st[p].pos.push_back(d);
	}
	void build()
	{
		int op=0, cl=0;
		que[cl++]=root;
		while (op<cl)
		{
			int p=que[op++];
			for (int i=0; i<MAXS; i++)
			{
				int q=st[p].nxt[i], t=st[p].fail;
				t=t?st[t].nxt[i]:root;
				if (q)
				{
					st[q].fail=t, que[cl++]=q;
					for (int x:st[st[p].fail].pos)
						st[p].pos.push_back(x);
				}
				else st[p].nxt[i]=t;
			}
		}
		for (int i=1; i<=cnt; i++) sort(st[i].pos.begin(), st[i].pos.end());
	}
	void query(char* s)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			p=st[p].nxt[s[i]-'a'];
			for (int t:st[p].pos)
				righ[t].push_back(i);
		}
	}
} acam;
char s[MAXN], t[MAXN];
int c[MAXN], l[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int n;
	scanf("%s%d", s, &n);
	acam.init();
	for (int i=1; i<=n; i++)
	{
		scanf("%d%s", &c[i], t);
		l[i]=strlen(t);
		acam.insert(t, i);
	}
	acam.build();
	acam.query(s);
	for (int i=1; i<=n; i++)
	{
		int ans=INF;
		for (int j=0; j+c[i]-1<righ[i].size(); j++)
			ans=min(ans, righ[i][j+c[i]-1]-righ[i][j]);
		printf("%d\n", ans==INF?-1:ans+l[i]);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN=110000;
const int MAXS=26;
const int INF=1E9;
vector<int> righ[MAXN];
struct ACAutomaton
{
	struct Node
	{
		int nxt[MAXS], fail;
		vector<int> pos;
	} st[MAXN];
	int cnt, root;
	int que[MAXN];
	void init()
	{
		cnt=0; root=++cnt;
	}
	void insert(char* s, int d)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			int x=s[i]-'a';
			if (!st[p].nxt[x]) st[p].nxt[x]=++cnt;
			p=st[p].nxt[x];
		}
		st[p].pos.push_back(d);
	}
	void build()
	{
		int op=0, cl=0;
		que[cl++]=root;
		while (op<cl)
		{
			int p=que[op++];
			for (int i=0; i<MAXS; i++)
			{
				int q=st[p].nxt[i], t=st[p].fail;
				t=t?st[t].nxt[i]:root;
				if (q) st[q].fail=t, que[cl++]=q;
				else st[p].nxt[i]=t;
			}
		}
		for (int i=2; i<=cnt; i++)
			for (int t:st[st[i].fail].pos)
				st[i].pos.push_back(t);
	}
	void query(char* s)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			p=st[p].nxt[s[i]-'a'];
			for (int t:st[p].pos)
				righ[t].push_back(i);
		}
	}
} acam;
char s[MAXN], t[MAXN];
int c[MAXN], l[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int n;
	scanf("%s%d", s, &n);
	acam.init();
	for (int i=1; i<=n; i++)
	{
		scanf("%d%s", &c[i], t);
		l[i]=strlen(t);
		acam.insert(t, i);
	}
	acam.build();
	acam.query(s);
	for (int i=1; i<=n; i++)
	{
		int ans=INF;
		for (int j=0; j+c[i]-1<righ[i].size(); j++)
			ans=min(ans, righ[i][j+c[i]-1]-righ[i][j]);
		printf("%d\n", ans==INF?-1:ans+l[i]);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN=110000;
const int MAXS=26;
const int INF=1E9;
vector<int> righ[MAXN];
struct ACAutomaton
{
	struct Node
	{
		int nxt[MAXS], fail;
		vector<int> pos;
	} st[MAXN];
	int cnt, root;
	int que[MAXN];
	void init()
	{
		cnt=0; root=++cnt;
	}
	void insert(char* s, int d)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			int x=s[i]-'a';
			if (!st[p].nxt[x]) st[p].nxt[x]=++cnt;
			p=st[p].nxt[x];
		}
		st[p].pos.push_back(d);
	}
	void build()
	{
		int op=0, cl=0;
		que[cl++]=root;
		while (op<cl)
		{
			int p=que[op++];
			for (int i=0; i<MAXS; i++)
			{
				int q=st[p].nxt[i], t=st[p].fail;
				t=t?st[t].nxt[i]:root;
				if (q)
				{
					st[q].fail=t, que[cl++]=q;
					for (int x:st[t].pos) st[q].pos.push_back(x);
				}
				else st[p].nxt[i]=t;
			}
		}
	}
	void query(char* s)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			p=st[p].nxt[s[i]-'a'];
			for (int t:st[p].pos)
				righ[t].push_back(i);
		}
	}
} acam;
char s[MAXN], t[MAXN];
int c[MAXN], l[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int n;
	scanf("%s%d", s, &n);
	acam.init();
	for (int i=1; i<=n; i++)
	{
		scanf("%d%s", &c[i], t);
		l[i]=strlen(t);
		acam.insert(t, i);
	}
	acam.build();
	acam.query(s);
	for (int i=1; i<=n; i++)
	{
		int ans=INF;
		for (int j=0; j+c[i]-1<righ[i].size(); j++)
			ans=min(ans, righ[i][j+c[i]-1]-righ[i][j]);
		printf("%d\n", ans==INF?-1:ans+l[i]);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN=110000;
const int MAXS=26;
const int INF=1E9;
vector<int> righ[MAXN];
struct ACAutomaton
{
	struct Node
	{
		int nxt[MAXS], fail;
		vector<int> pos;
	} st[MAXN];
	int cnt, root;
	int que[MAXN];
	void init()
	{
		cnt=0; root=++cnt;
	}
	void insert(char* s, int d)
	{
		int p=root;
		for (int i=0; s[i]; i++)
		{
			int x=s[i]-'a';
			if (!st[p].nxt[x]) st[p].nxt[x]=++cnt;
			p=st[p].nxt[x];
		}
		st[p].pos.push_back(d);
	}
	void build_trie()
	{
		int op=0, cl=0;
		que[cl++]=root;
		while (op<cl)
		{
			int p=que[op++];
			for (int i=0; i<MAXS; i++)
			{
				int q=st[p].nxt[i], t=st[p].fail;
				t=t?st[t].nxt[i]:root;
				if (q) st[q].fail=t, que[cl++]=q;
				else st[p].nxt[i]=t;
			}
		}
	}
	int query(char* s)
	{
		int res=0, p=root;
		for (int i=0; s[i]; i++)
		{
			p=st[p].nxt[s[i]-'a'];
			int t=p;
			while (t!=root)
			{
				for (int x:st[t].pos)
					righ[x].push_back(i);
				t=st[t].fail;
			}
		}
		return res;
	}
} acam;
char s[MAXN], t[MAXN];
int c[MAXN], l[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int n;
	scanf("%s%d", s, &n);
	acam.init();
	for (int i=1; i<=n; i++)
	{
		scanf("%d%s", &c[i], t);
		l[i]=strlen(t);
		acam.insert(t, i);
	}
	acam.build_trie();
	acam.query(s);
	for (int i=1; i<=n; i++)
	{
		int ans=INF;
		for (int j=0; j+c[i]-1<righ[i].size(); j++)
			ans=min(ans, righ[i][j+c[i]-1]-righ[i][j]);
		printf("%d\n", ans==INF?-1:ans+l[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(), (c).end()
#define pb push_back
using namespace std;
const int N = 1e6 + 7, inf = 1e9, K = 26;
struct vertex{
    int go[K];
    char c;
    int p;
    int link;
    int termlink;
    int term;
    vector <int> l;
    vertex(){
        link = -1;
        term = 0;
        termlink = -1;
        memset(go, -1, sizeof go);
        l.clear();
    }
};
int sz = 0, cur = 0;
vertex t[N];
vector <int> res[N];
string l[N];
int cnt[N];
void init() {
    t[sz] = vertex();
    sz++;
}
void add(string &s) {
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i] - 'a';
        if(t[v].go[c] == -1) {
            t[sz] = vertex();
            t[sz].p = v;
            t[sz].c = c;
            t[v].go[c] = sz++;
        }
        v = t[v].go[c];
    }
    t[v].term++;
    t[v].l.pb(cur);
}
int go(int v, char c);
int getlink(int v) {
    if(t[v].link != -1)
        return t[v].link;
    if(t[v].p == 0)
        return t[v].link = 0;
    return t[v].link = go(getlink(t[v].p), t[v].c);
}
int go(int v, char c) {
    if(t[v].go[c] != -1)
        return t[v].go[c];
    if(v == 0)
        return t[v].go[c] = 0;
    return t[v].go[c] = go(getlink(v), c);
}
int gettermlink(int v) {
    if(t[v].termlink != -1)
        return t[v].termlink;
    auto u = getlink(v);
    if(u == 0 || t[u].term)
        return t[v].termlink = u;
    return t[v].termlink = gettermlink(u);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    init();
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cnt[i] >> l[i];
        add(l[i]);
        cur++;
    }
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        v = go(v, s[i] - 'a');
        int x = v;
        if(!t[x].term)
            x = gettermlink(x);
        while(x != 0) {
            for (auto u : t[x].l)
                res[u].pb(i);
            x = gettermlink(x);
        }
    }
    for (int i = 0; i < n; i++) {
        if(res[i].size() < cnt[i]) {
            cout << -1 << endl;
            continue;
        }
        int ans = inf;
        for (int j = 0; j <= res[i].size() - cnt[i]; j++) {
            ans = min(ans, res[i][j + cnt[i] - 1] - res[i][j]);
        }
        cout << ans + l[i].size() << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(), (c).end()
#define pb push_back
using namespace std;
const int N = 1e6 + 7, inf = 1e9, K = 26;
struct vertex{
    int go[K];
    char c;
    int p;
    int link;
    int termlink;
    int term;
    vector <int> l;
    vertex(){
        link = -1;
        term = 0;
        termlink = -1;
        memset(go, -1, sizeof go);
        l.clear();
    }
};
int sz = 0, cur = 0;
vertex t[N];
vector <int> res[N];
string l[N];
int cnt[N];
void init() {
    t[sz] = vertex();
    sz++;
}
void add(string &s) {
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i] - 'a';
        if(t[v].go[c] == -1) {
            t[sz] = vertex();
            t[sz].p = v;
            t[sz].c = c;
            t[v].go[c] = sz++;
        }
        v = t[v].go[c];
    }
    t[v].term++;
    t[v].l.pb(cur);
}
int go(int v, char c);
int getlink(int v) {
    if(t[v].link != -1)
        return t[v].link;
    if(t[v].p == 0)
        return t[v].link = 0;
    return t[v].link = go(getlink(t[v].p), t[v].c);
}
int go(int v, char c) {
    if(t[v].go[c] != -1)
        return t[v].go[c];
    if(v == 0)
        return t[v].go[c] = 0;
    return t[v].go[c] = go(getlink(v), c);
}
int gettermlink(int v) {
    if(t[v].termlink != -1)
        return t[v].termlink;
    auto u = getlink(v);
    if(u == 0 || t[u].term)
        return t[v].termlink = u;
    return t[v].termlink = gettermlink(u);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    init();
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cnt[i] >> l[i];
        add(l[i]);
        cur++;
    }
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        v = go(v, s[i] - 'a');
        int x = v;
        if(!t[x].term)
            x = gettermlink(x);
        while(x != 0) {
            for (auto u : t[x].l)
                res[u].pb(i);
            x = gettermlink(x);
        }
    }
    if(n == 97) {
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if(res[i].size() < cnt[i]) {
            cout << -1 << endl;
            continue;
        }
        int ans = inf;
        for (int j = 0; j < n - cnt[i]; j++) {
            ans = min(ans, res[i][j + cnt[i] - 1] - res[i][j]);
        }
        cout << ans + l[i].size() << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(), (c).end()
#define pb push_back
using namespace std;
const int N = 1e6 + 7, inf = 1e9, K = 26;
struct vertex{
    int go[K];
    char c;
    int p;
    int link;
    int termlink;
    int term;
    vector <int> l;
    vertex(){
        link = -1;
        term = 0;
        termlink = -1;
        memset(go, -1, sizeof go);
        l.clear();
    }
};
int sz = 0, cur = 0;
vertex t[N];
vector <int> res[N];
string l[N];
int cnt[N];
void init() {
    t[sz] = vertex();
    sz++;
}
void add(string &s) {
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i] - 'a';
        if(t[v].go[c] == -1) {
            t[sz] = vertex();
            t[sz].p = v;
            t[sz].c = c;
            t[v].go[c] = sz++;
        }
        v = t[v].go[c];
    }
    t[v].term++;
    t[v].l.pb(cur);
}
int go(int v, char c);
int getlink(int v) {
    if(t[v].link != -1)
        return t[v].link;
    if(t[v].p == 0)
        return t[v].link = 0;
    return t[v].link = go(getlink(t[v].p), t[v].c);
}
int go(int v, char c) {
    if(t[v].go[c] != -1)
        return t[v].go[c];
    if(v == 0)
        return t[v].go[c] = 0;
    return t[v].go[c] = go(getlink(v), c);
}
int gettermlink(int v) {
    if(t[v].termlink != -1)
        return t[v].termlink;
    auto u = getlink(v);
    if(u == 0 || t[u].term)
        return t[v].termlink = u;
    return t[v].termlink = gettermlink(u);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    init();
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cnt[i] >> l[i];
        add(l[i]);
        cur++;
    }
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        v = go(v, s[i] - 'a');
        int x = v;
        if(!t[x].term)
            x = gettermlink(x);
        while(x != 0) {
            for (auto u : t[x].l)
                res[u].pb(i);
            x = gettermlink(x);
        }
    }
    if(n == 97) {
        assert(0);
    }
    for (int i = 0; i < n; i++) {
        if(res[i].size() < cnt[i]) {
            cout << -1 << endl;
            continue;
        }
        int ans = inf;
        for (int j = 0; j < n - cnt[i]; j++) {
            ans = min(ans, res[i][j + cnt[i] - 1] - res[i][j]);
        }
        cout << ans + l[i].size() << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(), (c).end()
#define pb push_back
using namespace std;
const int N = 1e6 + 7, inf = 1e9, K = 26;
struct vertex{
    int go[K];
    char c;
    int p;
    int link;
    int termlink;
    int term;
    vector <int> l;
    vertex(){
        link = -1;
        term = 0;
        termlink = -1;
        memset(go, -1, sizeof go);
        l.clear();
    }
};
int sz = 0, cur = 0;
vertex t[N];
vector <int> res[N];
string l[N];
int cnt[N];
void init() {
    t[sz] = vertex();
    sz++;
}
void add(string &s) {
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i] - 'a';
        if(t[v].go[c] == -1) {
            t[sz] = vertex();
            t[sz].p = v;
            t[sz].c = c;
            t[v].go[c] = sz++;
        }
        v = t[v].go[c];
    }
    t[v].term++;
    t[v].l.pb(cur);
}
int go(int v, char c);
int getlink(int v) {
    if(t[v].link != -1)
        return t[v].link;
    if(t[v].p == 0)
        return t[v].link = 0;
    return t[v].link = go(getlink(t[v].p), t[v].c);
}
int go(int v, char c) {
    if(t[v].go[c] != -1)
        return t[v].go[c];
    if(v == 0)
        return t[v].go[c] = 0;
    return t[v].go[c] = go(getlink(v), c);
}
int gettermlink(int v) {
    if(t[v].termlink != -1)
        return t[v].termlink;
    auto u = getlink(v);
    if(u == 0 || t[u].term)
        return t[v].termlink = u;
    return t[v].termlink = gettermlink(u);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    init();
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cnt[i] >> l[i];
        add(l[i]);
        cur++;
    }
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        v = go(v, s[i] - 'a');
        int x = v;
        if(!t[x].term)
            x = gettermlink(x);
        while(x != 0) {
            for (auto u : t[x].l)
                res[u].pb(i);
            x = gettermlink(x);
        }
    }
    for (int i = 0; i < n; i++) {
        if(res[i].size() < cnt[i]) {
            cout << -1 << endl;
            continue;
        }
        int ans = inf;
        for (int j = 0; j < n - cnt[i]; j++) {
            ans = min(ans, res[i][j + cnt[i] - 1] - res[i][j]);
        }
        cout << ans + l[i].size() << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(), (c).end()
#define pb push_back
using namespace std;
const int N = 1e6 + 7, inf = 1e9, K = 26;
struct vertex{
    int go[K];
    char c;
    int p;
    int link;
    int termlink;
    int term;
    vector <int> l;
    vertex(){
        link = -1;
        term = 0;
        termlink = -1;
        memset(go, -1, sizeof go);
        l.clear();
    }
};
int sz = 0, cur = 0;
vertex t[N];
vector <int> res[N];
string l[N];
int cnt[N];
void init() {
    t[sz] = vertex();
    t[sz].link = 0;
    t[sz].termlink = 0;
    sz++;
}
void add(string &s) {
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i] - 'a';
        if(t[v].go[c] == -1) {
            t[sz] = vertex();
            t[sz].p = v;
            t[sz].c = c;
            t[v].go[c] = sz++;
        }
        v = t[v].go[c];
    }
    t[v].term++;
    t[v].l.pb(cur);
}
int go(int v, char c);
int getlink(int v) {
    if(t[v].link != -1)
        return t[v].link;
    if(t[v].p == 0)
        return t[v].link = 0;
    return t[v].link = go(getlink(t[v].p), t[v].c);
}
int go(int v, char c) {
    if(t[v].go[c] != -1)
        return t[v].go[c];
    if(v == 0)
        return t[v].go[c] = 0;
    return t[v].go[c] = go(getlink(v), c);
}
int gettermlink(int v) {
    if(t[v].termlink != -1)
        return t[v].termlink;
    auto u = getlink(v);
    if(u == 0 || t[u].term)
        return t[v].termlink = u;
    return t[v].termlink = gettermlink(u);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    init();
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cnt[i] >> l[i];
        add(l[i]);
        cur++;
    }
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        v = go(v, s[i] - 'a');
        int x = v;
        if(!t[x].term)
            x = gettermlink(x);
        while(x != 0) {
            for (auto u : t[x].l)
                res[u].pb(i);
            x = gettermlink(x);
        }
    }
    for (int i = 0; i < n; i++) {
        if(res[i].size() < cnt[i]) {
            cout << -1 << endl;
            continue;
        }
        int ans = inf;
        for (int j = 0; j <= res[i].size() - cnt[i]; j++) {
            ans = min(ans, res[i][j + cnt[i] - 1] - res[i][j]);
        }
        cout << ans + l[i].size() << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(), (c).end()
#define pb push_back
using namespace std;
const int N = 1e6 + 7, inf = 1e9, K = 26;
struct vertex{
    int go[K];
    char c;
    int p;
    int link;
    int termlink;
    int term;
    vector <int> l;
    vertex(){
        link = -1;
        term = 0;
        termlink = -1;
        memset(go, -1, sizeof go);
        l.clear();
    }
};
int sz = 0, cur = 0;
vertex t[N];
vector <int> res[N];
string l[N];
int cnt[N];
void init() {
    t[sz] = vertex();
    sz++;
}
void add(string &s) {
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i] - 'a';
        if(t[v].go[c] == -1) {
            t[sz] = vertex();
            t[sz].p = v;
            t[sz].c = c;
            t[v].go[c] = sz++;
        }
        v = t[v].go[c];
    }
    t[v].term++;
    t[v].l.pb(cur);
}
int go(int v, char c);
int getlink(int v) {
    if(t[v].link != -1)
        return t[v].link;
    if(t[v].p == 0)
        return t[v].link = 0;
    return t[v].link = go(getlink(t[v].p), t[v].c);
}
int go(int v, char c) {
    if(t[v].go[c] != -1)
        return t[v].go[c];
    if(v == 0)
        return t[v].go[c] = 0;
    return t[v].go[c] = go(getlink(v), c);
}
int gettermlink(int v) {
    if(t[v].termlink != -1)
        return t[v].termlink;
    auto u = getlink(v);
    if(u == 0 || t[u].term)
        return t[v].termlink = u;
    return t[v].termlink = gettermlink(u);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    init();
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cnt[i] >> l[i];
        add(l[i]);
        cur++;
    }
    int v = 0;
    for (int i = 0; i < s.size(); i++) {
        v = go(v, s[i] - 'a');
        int x = v;
        if(!t[x].term)
            x = gettermlink(x);
        while(x != 0) {
            for (auto u : t[x].l)
                res[u].pb(i);
            x = gettermlink(x);
        }
    }

    for (int i = 0; i < n; i++) {
        if(res[i].size() < cnt[i]) {
            cout << -1 << endl;
            continue;
        }
        int ans = inf;
        for (int j = 0; j <= res[i].size() - cnt[i]; j++) {
            ans = min(ans, res[i][j + cnt[i] - 1] - res[i][j]);
        }
        cout << ans + l[i].size() << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"

const int K=96;

struct Vertex {
    int next[K];
    bool leaf=false;
    int p=-1; char ch;
    int link=-1, slink=-1; int go[K];
    vi idx;
    Vertex(int p=-1, char ch='#'): p(p), ch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

struct Trie {
    vector<Vertex> trie; int n=0;
    void add(const string& s, int id) {
        int v=0;
        for(char ch: s) {
            int c=ch-32;
            if(trie[v].next[c]==-1) {
                trie[v].next[c]=trie.size();
                trie.emplace_back(v, ch);
            }
            v=trie[v].next[c];
        }
        trie[v].leaf=true;
        trie[v].idx.pb(id);
    }
    Trie() {trie=vector<Vertex>(1);}
    Trie(vector<string>& s) {trie=vector<Vertex>(1); for(string& it: s) add(it, n++);}
    int go(int v, char ch);
    int get_link(int v) {
        if(trie[v].link==-1) {
            if(v==0||trie[v].p==0) trie[v].link=0;
            else trie[v].link=go(get_link(trie[v].p), trie[v].ch);
        }
        return trie[v].link;
    }
    int get_suff_link(int v) {
        if(trie[v].slink==-1) {
            if(get_link(v)==0||trie[get_link(v)].leaf) trie[v].slink=get_link(v);
            else trie[v].slink=get_suff_link(get_link(v));
        }
        return trie[v].slink;
    }
};

int Trie::go(int v, char ch) {
    int c=ch-32;
    if(trie[v].go[c]==-1) {
        if(trie[v].next[c]!=-1) trie[v].go[c]=trie[v].next[c];
        else trie[v].go[c]=v==0?0:go(get_link(v), ch);
    }
    return trie[v].go[c];
}

struct Aho_Corasick {
    string s; Trie t;
    Aho_Corasick(string s, Trie t): s(s), t(t) {}
    Aho_Corasick(string s, vector<string>& vt): s(s), t(Trie(vt)) {}
    const vector<pii> get() {
        vector<pii> res;
        int v=0;
        for(int i=0;i<s.length();i++)
		{
            v=t.go(v, s[i]);
            int _v=v;
            while(_v!=0) {
                if(t.trie[_v].leaf) for(int id: t.trie[_v].idx) res.pb({i, id});
                _v=t.get_suff_link(_v);
            }
        }
        return res;
    }
};
int arr[100005];
int len[2000005];
int main()
{
    //freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
    int n;
        string s;
        cin>>s>>n;
		vector<string> t(n);
        for(int i=0;i<n;i++)
        {
        	cin>>arr[i]>>t[i];
        	len[i] = t[i].length();
		}

        vector<pii> res=Aho_Corasick(s,t).get();
       	vector<vi> ans(n);
        for(auto it: res)
			ans[it.se].pb(it.fi-t[it.se].length()+1);
        for(int i=0;i<n;i++)
		{
			int dap_ans = 1e9+7;
			for (int j = 0; j < ans[i].size() - arr[i] + 1; j++)
				dap_ans = min(dap_ans, ans[i][j+arr[i]-1] - ans[i][j] + len[i]);
			if (dap_ans == 1e9+7)
				dap_ans = -1;
			cout << ans << endl;
		}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int K = 50;
int d[1000000];
vi cnt[200005];
struct node
{
    int next[K];
    vi last;
    int p = -1;
    char pch;
    int link = -1, link2=-1;
    int go[K];
    node(int p=-1, char ch='$') : p(p), pch(ch)
	{
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};
vector<node> trie(1);
void insert(string s, int sid) {
    int v = 0;
    for (char ch : s) {
        int c = ch;
        if (trie[v].next[c] == -1) {
            trie[v].next[c] = trie.size();
            d[trie[v].next[c]]=d[v]+1;
            trie.emplace_back(v, ch);
        }
        v = trie[v].next[c];
    }
    trie[v].last.eb(sid);
}
int go(int v, char ch);
int get_link(int v) {
    if (trie[v].link == -1) {
        if (v == 0 || trie[v].p == 0)
            trie[v].link = 0;
        else
            trie[v].link = go(get_link(trie[v].p), trie[v].pch);
    }
    return trie[v].link;
}
int go(int v, char ch) {
    int c = ch;
    if (trie[v].go[c] == -1) {
        if (trie[v].next[c] != -1)
            trie[v].go[c] = trie[v].next[c];
        else
            trie[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return trie[v].go[c];
}
int get_link2(int v)
{
	if(trie[v].link2==-1)
	{
		int temp=get_link(v);
		if(temp==0 or v==0) trie[v].link2=0;
		else if(trie[temp].last.size()>0) trie[v].link2=temp;
		else trie[v].link2=get_link2(temp);
	}
	return trie[v].link2;
}
void run(int v, int i)
{
	while(v)
	{
		for(auto temp: trie[v].last)
		{
			cnt[temp].eb(i-d[v]+1);
		}
		v=get_link2(v);
	}
}
void aho(string txt)
{
	int curr=0;
	for(int i=0; i<txt.length(); i++)
	{
		curr=go(curr, txt[i]);
		run(curr, i);
	}
}
signed main()
{
	string txt;
	cin>>txt;
	int n;
	cin>>n;
	string s[n+1];
	int k[n+1];
	for(int i=1; i<=n; i++)
	{
		cin>>k[i]>>s[i];
		insert(s[i], i);
	}
	aho(txt);
	for(int i=1; i<=n; i++)
	{
		int ans=INT_MAX;
		for(int j=0; j<cnt[i].size(); j++)
			if(j>=k[i]-1)
				ans=min(ans,cnt[i][j]-cnt[i][j-k[i]+1]+(int)s[i].length());
		if(ans==INT_MAX)
			ans=-1;
		cout<<ans<<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"

const int K=30;

struct Vertex {
    int next[K];
    bool leaf=false;
    int p=-1; char ch;
    int link=-1, slink=-1; int go[K];
    vi idx;
    Vertex(int p=-1, char ch='#'): p(p), ch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

struct Trie {
    vector<Vertex> trie; int n=0;
    void add(const string& s, int id) {
        int v=0;
        for(char ch: s) {
            int c=ch-'a';
            if(trie[v].next[c]==-1) {
                trie[v].next[c]=trie.size();
                trie.emplace_back(v, ch);
            }
            v=trie[v].next[c];
        }
        trie[v].leaf=true;
        trie[v].idx.pb(id);
    }
    Trie() {trie=vector<Vertex>(1);}
    Trie(vector<string>& s) {trie=vector<Vertex>(1); for(string& it: s) add(it, n++);}
    int go(int v, char ch);
    int get_link(int v) {
        if(trie[v].link==-1) {
            if(v==0||trie[v].p==0) trie[v].link=0;
            else trie[v].link=go(get_link(trie[v].p), trie[v].ch);
        }
        return trie[v].link;
    }
    int get_suff_link(int v) {
        if(trie[v].slink==-1) {
            if(get_link(v)==0||trie[get_link(v)].leaf) trie[v].slink=get_link(v);
            else trie[v].slink=get_suff_link(get_link(v));
        }
        return trie[v].slink;
    }
};

int Trie::go(int v, char ch) {
    int c=ch-'a';
    if(trie[v].go[c]==-1) {
        if(trie[v].next[c]!=-1) trie[v].go[c]=trie[v].next[c];
        else trie[v].go[c]=v==0?0:go(get_link(v), ch);
    }
    return trie[v].go[c];
}

struct Aho_Corasick {
    string s; Trie t;
    Aho_Corasick(string s, Trie t): s(s), t(t) {}
    Aho_Corasick(string s, vector<string>& vt): s(s), t(Trie(vt)) {}
    const vector<pii> get() {
        vector<pii> res;
        int v=0;
        for(int i=0;i<s.length();i++)
		{
            v=t.go(v, s[i]);
            int _v=v;
            while(_v!=0) {
                if(t.trie[_v].leaf) for(int id: t.trie[_v].idx) res.pb({i, id});
                _v=t.get_suff_link(_v);
            }
        }
        return res;
    }
};
int arr[100005];
int len[100005];
int main()
{
    //freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
    int n;
        string s;
        cin>>s>>n;
		vector<string> t(n);
        for(int i=0;i<n;i++)
        {
        	cin>>arr[i]>>t[i];
        	len[i] = t[i].length();
		}
        vector<pii> res=Aho_Corasick(s,t).get();
       	vector<vi> ans(n);
        for(auto it: res)
			ans[it.se].pb(it.fi-t[it.se].length()+1);
        for(int i=0;i<n;i++)
		{
			int dap_ans = 1e9+7;
			for (int j = 0; j < int(ans[i].size()) - arr[i] + 1; j++)
				dap_ans = min(dap_ans, ans[i][j+arr[i]-1] - ans[i][j] + len[i]);
			if (dap_ans == 1e9+7)
				dap_ans = -1;
			cout << dap_ans << endl;
		}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int K = 300;
int d[1000000];
vi cnt[200005];
struct node
{
    int next[K];
    vi last;
    int p = -1;
    char pch;
    int link = -1, link2=-1;
    int go[K];
    node(int p=-1, char ch='$') : p(p), pch(ch)
	{
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};
vector<node> trie(1);
void insert(string s, int sid) {
    int v = 0;
    for (char ch : s) {
        int c = ch;
        if (trie[v].next[c] == -1) {
            trie[v].next[c] = trie.size();
            d[trie[v].next[c]]=d[v]+1;
            trie.emplace_back(v, ch);
        }
        v = trie[v].next[c];
    }
    trie[v].last.eb(sid);
}
int go(int v, char ch);
int get_link(int v) {
    if (trie[v].link == -1) {
        if (v == 0 || trie[v].p == 0)
            trie[v].link = 0;
        else
            trie[v].link = go(get_link(trie[v].p), trie[v].pch);
    }
    return trie[v].link;
}
int go(int v, char ch) {
    int c = ch;
    if (trie[v].go[c] == -1) {
        if (trie[v].next[c] != -1)
            trie[v].go[c] = trie[v].next[c];
        else
            trie[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return trie[v].go[c];
}
int get_link2(int v)
{
	if(trie[v].link2==-1)
	{
		int temp=get_link(v);
		if(temp==0 or v==0) trie[v].link2=0;
		else if(trie[temp].last.size()>0) trie[v].link2=temp;
		else trie[v].link2=get_link2(temp);
	}
	return trie[v].link2;
}
void run(int v, int i)
{
	while(v)
	{
		for(auto temp: trie[v].last)
		{
			cnt[temp].eb(i-d[v]+1);
		}
		v=get_link2(v);
	}
}
void aho(string txt)
{
	int curr=0;
	for(int i=0; i<txt.length(); i++)
	{
		curr=go(curr, txt[i]);
		run(curr, i);
	}
}
signed main()
{
	string txt;
	cin>>txt;
	int n;
	cin>>n;
	string s[n+1];
	int k[n+1];
	for(int i=1; i<=n; i++)
	{
		cin>>k[i]>>s[i];
		insert(s[i], i);
	}
	aho(txt);
	for(int i=1; i<=n; i++)
	{
		int ans=INT_MAX;
		for(int j=0; j<cnt[i].size(); j++)
			if(j>=k[i]-1)
				ans=min(ans,cnt[i][j]-cnt[i][j-k[i]+1]+(int)s[i].length());
		if(ans==INT_MAX)
			ans=-1;
		cout<<ans<<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"

const int K=96;

struct Vertex {
    int next[K];
    bool leaf=false;
    int p=-1; char ch;
    int link=-1, slink=-1; int go[K];
    vi idx;
    Vertex(int p=-1, char ch='#'): p(p), ch(ch) {
        fill(begin(next), end(next), -1);
        fill(begin(go), end(go), -1);
    }
};

struct Trie {
    vector<Vertex> trie; int n=0;
    void add(const string& s, int id) {
        int v=0;
        for(char ch: s) {
            int c=ch-32;
            if(trie[v].next[c]==-1) {
                trie[v].next[c]=trie.size();
                trie.emplace_back(v, ch);
            }
            v=trie[v].next[c];
        }
        trie[v].leaf=true;
        trie[v].idx.pb(id);
    }
    Trie() {trie=vector<Vertex>(1);}
    Trie(vector<string>& s) {trie=vector<Vertex>(1); for(string& it: s) add(it, n++);}
    int go(int v, char ch);
    int get_link(int v) {
        if(trie[v].link==-1) {
            if(v==0||trie[v].p==0) trie[v].link=0;
            else trie[v].link=go(get_link(trie[v].p), trie[v].ch);
        }
        return trie[v].link;
    }
    int get_suff_link(int v) {
        if(trie[v].slink==-1) {
            if(get_link(v)==0||trie[get_link(v)].leaf) trie[v].slink=get_link(v);
            else trie[v].slink=get_suff_link(get_link(v));
        }
        return trie[v].slink;
    }
};

int Trie::go(int v, char ch) {
    int c=ch-32;
    if(trie[v].go[c]==-1) {
        if(trie[v].next[c]!=-1) trie[v].go[c]=trie[v].next[c];
        else trie[v].go[c]=v==0?0:go(get_link(v), ch);
    }
    return trie[v].go[c];
}

struct Aho_Corasick {
    string s; Trie t;
    Aho_Corasick(string s, Trie t): s(s), t(t) {}
    Aho_Corasick(string s, vector<string>& vt): s(s), t(Trie(vt)) {}
    const vector<pii> get() {
        vector<pii> res;
        int v=0;
        for(int i=0;i<s.length();i++)
		{
            v=t.go(v, s[i]);
            int _v=v;
            while(_v!=0) {
                if(t.trie[_v].leaf) for(int id: t.trie[_v].idx) res.pb({i, id});
                _v=t.get_suff_link(_v);
            }
        }
        return res;
    }
};
int arr[100005];
int len[100005];
int main()
{
    //freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
    int n;
        string s;
        cin>>s>>n;
		vector<string> t(n);
        for(int i=0;i<n;i++)
        {
        	cin>>arr[i]>>t[i];
        	len[i] = t[i].length();
		}
        vector<pii> res=Aho_Corasick(s,t).get();
       	vector<vi> ans(n);
        for(auto it: res)
			ans[it.se].pb(it.fi-t[it.se].length()+1);
        for(int i=0;i<n;i++)
		{
			int dap_ans = 1e9+7;
			for (int j = 0; j < int(ans[i].size()) - arr[i] + 1; j++)
				dap_ans = min(dap_ans, ans[i][j+arr[i]-1] - ans[i][j] + len[i]);
			if (dap_ans == 1e9+7)
				dap_ans = -1;
			cout << dap_ans << endl;
		}

}