#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[30];
string t;
vector<int> v[30];
int main() {
  cin >> n >> t >> q;
  for (int i = 0; i < n; i++) {
    v[t[i] - 'a'].push_back(i);
  }
  while (q--) {
    memset(a, 0, sizeof(a));
    string s;
    cin >> s;
    int mx = 0;
    for (int i = 0; i < s.size(); i++) {
      mx = max(mx, v[s[i] - 'a'][a[s[i] - 'a']] + 1);
      a[s[i] - 'a']++;
    }
    cout << mx << endl;
  }
}
