#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> freq1, vector<int> freq2) {
  for (int i = 0; i < 26; i += 1) {
    if (freq2[i] > freq1[i]) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int> > freq1(n, vector<int>(26, 0));
  vector<int> freq(26, 0);
  for (int i = 0; i < n; i += 1) {
    freq[s[i] - 'a']++;
    freq1[i] = freq;
  }
  int m;
  cin >> m;
  while (m--) {
    string t;
    cin >> t;
    vector<int> freq2(26, 0);
    for (int i = 0; i < t.length(); i += 1) freq2[t[i] - 'a']++;
    int lo = 0, hi = n - 1;
    while (lo < hi) {
      int mid = lo + (hi - lo) / 2;
      if (check(freq1[mid], freq2)) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    cout << lo + 1 << "\n";
  }
  return 0;
}
