#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  unordered_map<char, vector<int>> datas;
  for (int i = 0; i < s.length(); ++i) {
    datas[s[i]].emplace_back(i);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string kalimat;
    cin >> kalimat;
    int indeks = 0000;
    int lol[26] = {0};
    for (auto &c : kalimat) {
      lol[c - 'a']++;
    }
    for (int j = 0; j < 26; j++) {
      if (lol[j] > 0) indeks = max(indeks, datas[(char)(j + 97)][lol[j] - 1]);
    }
    cout << indeks + 1 << endl;
  }
}
