#include <bits/stdc++.h>
using namespace std;
long long int f[26][200001];
long long int check(long long int mid, long long int H[26]) {
  long long int p = 0;
  for (long long int i = 0; i < 26; ++i) {
    if (H[i] <= f[i][mid]) {
      p++;
    }
  }
  if (p == 26) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, n;
  cin >> n;
  string s, r;
  cin >> s;
  cin >> t;
  for (long long int i = 0; i < s.size(); ++i) {
    f[s[i] - 'a'][i] = 1;
  }
  for (long long int i = 1; i < s.size(); ++i) {
    for (long long int j = 0; j < 26; ++j) {
      f[j][i] += f[j][i - 1];
    }
  }
  while (t--) {
    cin >> r;
    long long int H[26] = {0};
    for (long long int i = 0; i < r.size(); ++i) {
      H[r[i] - 'a']++;
    }
    long long int l = 0;
    long long int h = n - 1;
    long long int k;
    while (l <= h) {
      long long int mid = (l + h) / 2;
      if (check(mid, H) == 1) {
        h = mid - 1;
        k = mid;
      } else {
        l = mid + 1;
      }
    }
    cout << k + 1 << "\n";
  }
}
