/**
KMP
Date: January 18, 2017
Runtime: 1.080/3.000s
*/
#include <bits/stdc++.h>
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define FE(x, v) for (typeof v.begin() x = v.begin(); x != v.end(); ++x)
#define FOR(i, a, n) for(int i = (a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define el '\n'
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int M = 1005;
string t, p;
int tc, n, m, q, b[M];
inline void pp() {
m = (int)p.size();
int i = 0, j = -1; b[0] = -1;
while (i < m) {
while (j >= 0 && p[i] != p[j]) j = b[j];
++i; ++j; b[i] = j;
}
}
inline bool kmp() {
n = (int)t.size();
int i = 0, j = 0;
while (i < n) {
while (j >= 0 && t[i] != p[j]) j = b[j];
++i; ++j;
if (j == m) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> tc;
REP(ttc, tc) {
cin >> t >> q;
REP(qq, q) {
cin >> p; pp();
cout << (kmp() ? "y\n" : "n\n");
}
}
return 0;
}
LyoqCktNUAoKRGF0ZTogSmFudWFyeSAxOCwgMjAxNwpSdW50aW1lOiAxLjA4MC8zLjAwMHMKICovCgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KCiNkZWZpbmUgUkVBRChmKSBmcmVvcGVuKGYsICJyIiwgc3RkaW4pCiNkZWZpbmUgV1JJVEUoZikgZnJlb3BlbihmLCAidyIsIHN0ZG91dCkKI2RlZmluZSBGRSh4LCB2KSBmb3IgKHR5cGVvZiB2LmJlZ2luKCkgeCA9IHYuYmVnaW4oKTsgeCAhPSB2LmVuZCgpOyArK3gpCiNkZWZpbmUgRk9SKGksIGEsIG4pIGZvcihpbnQgaSA9IChhKTsgaSA8IChpbnQpKG4pOyArK2kpCiNkZWZpbmUgUkVQKGksIG4pIEZPUihpLCAwLCBuKQojZGVmaW5lIGVsICdcbicKI2RlZmluZSBwYiBwdXNoX2JhY2sKCnVz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