#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool cando(string &s, string &station, int inx) {
	vector<int> dic(26, -1); // what letter correspond to what
	vector<int> dicR(26, -1);
	for (int j = 0; j < station.size(); j++) {
		int charStation = station[j] - 'a';
		int charS = s[j+inx] - 'A';
		// if character charStation already appeared, but charS didn't
		//  or vice versa
		if ((dic[charStation] == -1) != (dicR[charS] == -1))
			return false;
		// if charS already maps to something different
		if (dicR[charS] != -1 && dicR[charS] != charStation)
			return false;
		// if charStation already maps to something different
		if (dic[charStation] != -1 && dic[charStation] != charS)
			return false;
		dic[charStation] = charS;
		dicR[charS] = charStation;
	}
	return true;
}

int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	for (int i = 0; i < N; i++) {
		string station;
		cin >> station;
		bool found = false;
		for (int j = 0; j + station.size() <= s.size(); j++) {
			if (cando(s, station, j)) {
				printf("%d\n", j);
				found = true;
				break;
			}
		}
		if (!found) {
			printf("-\n");
		}
	}
	return 0;
}
