/* Author : Triet Do Thanh - FPT University */
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
typedef pair<int, int> ii;
const int N = 1e6 + 7;
const long long oo = 1e18 + 7;
const long long MOD = 1e9 + 7;
const int base = 311;
int n, q, k;
int dp[(1 << 15)];
int h[2][N], pw[N], a[N];
int get(int op, int l, int r) {
if (op == 1) {
int _l = l;
l = n - r + 1;
r = n - _l + 1;
}
return (h[op][r] - h[op][l - 1] * pw[r - l + 1] + MOD * MOD) % MOD;
}
bool check(int l, int r) {
return get(0, l, r) == get(1, l, r);
}
#define bit(mask, i) (mask & (1ll << i))
#define on(mask, i) (mask | (1ll << i))
#define off(mask, i) (mask | ~(1ll << i))
void solve() {
string s, t;
cin >> s;
n = s.size();
t = s;
reverse(t.begin(), t.end());
s = " " + s;
t = " " + t;
pw[0] = 1;
for (int i = 1; i <= n; ++i) {
h[0][i] = (h[0][i - 1] * base + s[i] - 'a' + 1) % MOD;
h[1][i] = (h[1][i - 1] * base + t[i] - 'a' + 1) % MOD;
pw[i] = (pw[i - 1] * base) % MOD;
}
cin >> q;
while (q--) {
int k; cin >> k;
for (int i = 1; i <= k; ++i) cin >> a[i];
for (int mask = 0; mask < (1 << k); ++mask) {
dp[mask] = oo;
}
dp[0] = 0;
for (int mask = 0; mask < (1 << k); ++mask) {
for (int i = 1; i <= k; ++i) {
if (bit(mask, i - 1)) continue;
int len = a[i];
for (int j = dp[mask] + 1; j <= n - a[i] + 1; ++j) {
if (check(j, j + len - 1)) {
dp[on(mask, i - 1)] = min(dp[on(mask, i - 1)], j + len - 1);
break;
}
}
}
}
if (dp[(1 << k) - 1] != oo) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
#define TASK "test"
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
solve();
return 0;
}
LyogQXV0aG9yIDogVHJpZXQgRG8gVGhhbmggLSBGU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ICBzID0gIiAiICsgczsKICAgdCA9ICIgIiArIHQ7CiAgIHB3WzBdID0gMTsKICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgIGhbMF1baV0gPSAoaFswXVtpIC0gMV0gKiBiYXNlICsgc1tpXSAtICdhJyArIDEpICUgTU9EOwogICAgICBoWzFdW2ldID0gKGhbMV1baSAtIDFdICogYmFzZSArIHRbaV0gLSAnYScgKyAxKSAlIE1PRDsKICAgICAgcHdbaV0gPSAocHdbaSAtIDFdICogYmFzZSkgJSBNT0Q7CiAgIH0KICAgY2luID4+IHE7CiAgIHdoaWxlIChxLS0pIHsgCiAgICAgIGludCBrOyBjaW4gPj4gazsKICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gazsgKytpKSBjaW4gPj4gYVtpXTsKICAgICAgZm9yIChpbnQgbWFzayA9IDA7IG1hc2sgPCAoMSA8PCBrKTsgKyttYXNrKSB7CiAgICAgICAgIGRwW21hc2tdID0gb287CiAgICAgIH0KICAgICAgZHBbMF0gPSAwOwogICAgICBmb3IgKGludCBtYXNrID0gMDsgbWFzayA8ICgxIDw8IGspOyArK21hc2spIHsKICAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gazsgKytpKSB7CiAgICAgICAgICAgIGlmIChiaXQobWFzaywgaSAtIDEpKSBjb250aW51ZTsKICAgICAgICAgICAgaW50IGxlbiA9IGFbaV07CiAgICAgICAgICAgIGZvciAoaW50IGogPSBkcFttYXNrXSArIDE7IGogPD0gbiAtIGFbaV0gKyAxOyArK2opIHsKICAgICAgICAgICAgICAgaWYgKGNoZWNrKGosIGogKyBsZW4gLSAxKSkgewogICAgICAgICAgICAgICAgICBkcFtvbihtYXNrLCBpIC0gMSldID0gbWluKGRwW29uKG1hc2ssIGkgLSAxKV0sIGogKyBsZW4gLSAxKTsgCiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgfQogICAgICB9CiAgICAgIGlmIChkcFsoMSA8PCBrKSAtIDFdICE9IG9vKSBjb3V0IDw8ICJZRVMiIDw8IGVuZGw7CiAgICAgIGVsc2UgY291dCA8PCAiTk8iIDw8IGVuZGw7CiAgIH0KfQoKI2RlZmluZSBUQVNLICJ0ZXN0IgoKc2lnbmVkIG1haW4oKQp7CiAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpLCBjaW4udGllKDApLCBjb3V0LnRpZSgwKTsKICAgaWYgKGZvcGVuKCJpbnB1dC50eHQiLCAiciIpKSB7CiAgICAgIGZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pOwogICAgICBmcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICB9CiAgIHNvbHZlKCk7CiAgIHJldHVybiAwOwp9