#include <bits/stdc++.h>
using namespace std;
map<int, int> M[200010], b;
int main() {
  int n, m, L;
  string str, str2;
  cin >> n;
  cin >> str;
  L = str.length();
  for (int i = 0; i < str.length(); ++i) {
    if (i != 0) M[i] = M[i - 1];
    M[i][str[i] - 'a']++;
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> str2;
    b.clear();
    for (int j = 0; j < str2.length(); ++j) b[str2[j] - 'a']++;
    int L = str2.length() - 1, R = str.length() - 1;
    int mid = (L + R) / 2;
    while (L < R) {
      int ans = 0;
      map<int, int>::iterator iter;
      for (iter = b.begin(); iter != b.end(); ++iter)
        if ((*iter).second > M[mid][(*iter).first]) break;
      if (iter == b.end()) {
        R = mid;
        mid = (L + R) / 2;
      } else {
        L = mid + 1;
        mid = (L + R) / 2;
      }
    }
    printf("%d\n", mid + 1);
  }
  return 0;
}
