#include <bits/stdc++.h>
using namespace std;
bool check(vector<long long> &v1, vector<long long> &v2) {
  for (long long k = 0; k < 26; k++) {
    if (v1[k] > v2[k]) {
      return false;
    }
  }
  return true;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<long long> > pre(n, vector<long long>(26, 0));
  pre[0][s[0] - 'a'] = 1;
  for (long long i = 1; i < n; i++) {
    for (long long j = 0; j < 26; j++) {
      pre[i][j] = pre[i - 1][j];
    }
    pre[i][s[i] - 'a']++;
  }
  long long t;
  cin >> t;
  for (long long j = 0; j < t; j++) {
    string w;
    cin >> w;
    vector<long long> word(26, 0);
    for (long long i = 0; i < w.size(); i++) {
      word[w[i] - 'a']++;
    }
    long long lower = -1;
    long long upper = n - 1;
    while (upper - lower > 1) {
      long long mid = (upper + lower) / 2;
      if (check(word, pre[mid])) {
        upper = mid;
      } else {
        lower = mid;
      }
    }
    cout << upper + 1 << "\n";
  }
}
