#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n;
  cin >> n;
  std::vector<vector<int>> letters(26, vector<int>{});
  for (int i = 0; i < s.size(); ++i) {
    int idx = s[i] - 'a';
    letters[idx].push_back(i);
  }
  while (n--) {
    string name;
    cin >> name;
    int maxPos = 0;
    int position[26] = {0};
    for (int i = 0; i < name.size(); ++i) {
      int idx = name[i] - 'a';
      maxPos = max(letters[idx][position[idx]++], maxPos);
    }
    cout << maxPos + 1 << endl;
  }
  return 0;
}
