贪心,和哈希没关系
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
//如果在不支持 avx2 的平台上将 avx2 换成 avx 或 SSE 之一
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline void divide() {sort(vx.begin(),vx.end());vx.erase(unique(vx.begin(),vx.end()),vx.end());}
inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
inline ll Lsqrt(ll x) { ll L = 1,R = 2e9;while(L + 1 < R){ll M = (L+R)/2;if(M*M <= x) L = M;else R = M;}return L;}
set<int> pos[26];
void solve()
{
int n,q;
cin>>n>>q;
VS g(q+1);
for(int i = 0; i <= q; ++i) cin>>g[i];
for(int i = 0; i < n; ++i) pos[g[0][i] - 'a'].insert(i);
for(int i = 1; i <= q; ++i)
{
int t = g[i].size();
int last = -1;
bool ok = true;
for(int j = 0;j < t; ++j)
{
auto it = pos[g[i][j]-'a'].upper_bound(last);
if(it == pos[g[i][j]-'a'].end())
ok = false;
else last = *it;
}
cout<<(ok?("YES\n"):("NO\n"));
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
//cin>>T;
while(T--)
{
solve();
}
}