#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int x[100005];
bool was[26];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> t;
  cin >> s;
  cin >> n;
  bool check = 0;
  int pos;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == '*') check = 1, pos = i;
  for (int i = 0; i < t.size(); i++) {
    was[t[i] - 'a'] = 1;
  }
  for (int i = 0; i < n; i++) {
    string p;
    cin >> p;
    if (!check && p.size() != s.size()) {
      cout << "NO" << endl;
      continue;
    }
    if (!check) {
      bool c = 0;
      for (int i = 0; i < s.size(); i++) {
        if (s[i] != p[i] && s[i] != '?') {
          c = 1;
          break;
        }
        if (s[i] == '?' && !was[p[i] - 'a']) {
          c = 1;
          break;
        }
      }
      if (c)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
      continue;
    }
    if (check) {
      if (p.size() + 1 < s.size()) {
        cout << "NO" << endl;
        continue;
      }
      bool c = 0;
      for (int i = 0; i < pos; i++) {
        if (s[i] == '?' && !was[p[i] - 'a']) {
          c = 1;
          break;
        }
        if (s[i] != p[i] && s[i] != '?') {
          c = 1;
          break;
        }
      }
      if (c) {
        cout << "NO" << endl;
        continue;
      }
      for (int i = pos; i < pos + p.size() - s.size() + 1; i++)
        if (was[p[i] - 'a']) {
          c = 1;
          break;
        }
      if (c) {
        cout << "NO" << endl;
        continue;
      }
      for (int i = pos + p.size() - s.size() + 1; i < p.size(); i++) {
        if (s[i - p.size() + s.size()] == '?' && !was[p[i] - 'a']) {
          c = 1;
          break;
        }
        if (s[i - p.size() + s.size()] != p[i] &&
            s[i - p.size() + s.size()] != '?') {
          c = 1;
          break;
        }
      }
      if (c) {
        cout << "NO" << endl;
        continue;
      }
      cout << "YES" << endl;
    }
  }
  return 0;
}
