#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long mod = 1e9 + 7;
long long n, m, s, t;
int num[maxn][26];
int sum[26];
inline bool check(int len) {
  bool flag = 1;
  for (int i = 0; i < 26; i++) {
    if (sum[i] > num[len][i]) flag = 0;
  }
  return flag;
}
int main() {
  cin >> n;
  string str;
  cin >> str;
  for (int i = 0; i < n; i++) {
    num[i][str[i] - 'a']++;
    for (int j = 0; j < 26; j++) {
      num[i][j] += num[i - 1][j];
    }
  }
  cin >> m;
  while (m--) {
    string a;
    cin >> a;
    memset(sum, 0, sizeof(sum));
    int len = a.length();
    for (int i = 0; i < len; i++) {
      sum[a[i] - 'a']++;
    }
    int u = -1;
    int l = len - 1, r = n - 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(mid))
        r = mid - 1;
      else
        l = mid + 1;
    }
    printf("%d\n", l + 1);
  }
  return 0;
}
