#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string st, t;
  cin >> st;
  int i, j;
  map<char, vector<int> > m;
  map<char, int> freq;
  for (i = 0; i < n; i++) {
    freq[st[i]]++;
    for (j = 0; j < 26; j++) {
      char ch = j + 'a';
      m[ch].push_back(freq[ch]);
    }
  }
  int frnd;
  cin >> frnd;
  while (frnd--) {
    int ans = -1;
    cin >> t;
    map<char, int> store;
    for (i = 0; t[i]; i++) store[t[i]]++;
    int l = 0;
    int r = n - 1;
    while (l <= r) {
      i = (l + r) / 2;
      bool flag = true;
      for (j = 0; j < 26; j++) {
        int x = m[j + 'a'][i];
        if (x < store[j + 'a']) {
          flag = false;
        }
      }
      if (flag == false) {
        l = i + 1;
      } else {
        ans = i;
        r = i - 1;
      }
    }
    cout << ans + 1 << endl;
  }
  return 0;
}
