#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, p, s, t;
  string ss, st;
  cin >> n >> st >> t;
  vector<int> v[100009];
  for (int i = 0; i < st.size(); ++i) {
    v[(int)st[i]].push_back(i);
  }
  while (t--) {
    cin >> ss;
    int mx = 0;
    int ar[255] = {0};
    for (int i = 0; i < ss.size(); ++i) {
      ar[ss[i]]++;
    }
    for (int i = 0; i < ss.size(); ++i) {
      mx = max(mx, v[ss[i]][ar[ss[i]] - 1]);
    }
    cout << mx + 1 << endl;
  }
  return 0;
}
