#include <bits/stdc++.h>
const int N = 2e5 + 5;
const int M = 5e4 + 5;
int n, m;
std::string s, t;
int sum[N][300], cnt[300];
int main() {
  scanf("%d", &n);
  std::cin >> s;
  scanf("%d", &m);
  sum[0][s[0]] = 1;
  for (int i = 1, l = s.size(); i < l; i++) {
    for (int j = 'a'; j <= 'z'; j++) sum[i][j] = sum[i - 1][j];
    sum[i][s[i]]++;
  }
  while (m--) {
    std::cin >> t;
    memset(cnt, 0, sizeof cnt);
    for (int i = 0, l = t.size(); i < l; i++) cnt[t[i]]++;
    int ans = 0;
    for (int i = 'a'; i <= 'z'; i++) {
      int l = 0, r = s.size() - 1, mid, res;
      while (l <= r) {
        mid = (l + r) >> 1;
        if (sum[mid][i] >= cnt[i])
          r = mid - 1, res = mid;
        else
          l = mid + 1;
      }
      ans = std::max(ans, res);
    }
    printf("%d\n", ans + 1);
  }
  return 0;
}
