/******************************************
* AUTHOR: BHUVNESH JAIN *
* INSTITUITION: BITS PILANI, PILANI *
******************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
const int MAX = 1e5 + 5;
const int LIM = 50;
const long long p1 = 31;
const long long mod = 999999937;
int n;
string s, p;
map<int,vector<int>> h[LIM];
int main() {
#ifndef ONLINE_JUDGE
// freopen("inp.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin >> s;
n = s.length();
int q, l, r, m;
int a, b, c, d;
for(int i = 0; i < n; ++i) {
a = 0;
for(int j = 0; j < 10; ++j) {
if(i+j >= n) break;
a = (1ll*a*p1)%mod + (s[i+j]-'a'+1);
a %= mod;
h[j][a].push_back(i);
}
}
cin >> q;
while(q--) {
cin >> l >> r >> p;
l -= 1;
r -= 1;
m = p.length();
b = 0, c = 0;
for(int i = 0; i < m; ++i) {
if (p[i] == '*') {
b += 1;
}
else {
c += 1;
}
}
if (b == m) {
//all *
printf("Yes\n");
continue;
}
if (c == m && (r-l+1) > m) {
//all alpha
printf("No\n");
continue;
}
if (c > (r-l+1)) {
//alpha count > size of substring
printf("No\n");
continue;
}
bool ans = 1;
int st = 0, lt = m-1;
b = l, c = r;
if (p[st] != '*') {
//case of inital character(s)
while(st < m && p[st] != '*') {
if (p[st] != s[b]) {
ans = 0;
break;
}
b += 1;
st += 1;
}
if (ans == 0) {
printf("No\n");
continue;
}
}
if (p[lt] != '*') {
//case of last character(s)
while(lt >= 0 && p[lt] != '*') {
if (p[lt] != s[c]) {
ans = 0;
break;
}
c -= 1;
lt -= 1;
}
if (ans == 0) {
printf("No\n");
continue;
}
}
//start and end character are *
if (st <= lt) {
assert(p[st] == '*');
assert(p[lt] == '*');
}
d = b;
for(int i = st; i < lt; ++i) {
if (p[i] == '*') {
int j = i;
while(j < m && p[j] == p[i]) {
j += 1;
}
i = j-1;
continue;
}
//case of fixed character
int j = i, cnt = -1;
a = 0;
while(j < m && p[j]!='*') {
a = (1ll*a*p1)%mod + (p[j]-'a'+1);
a %= mod;
j += 1;
cnt += 1;
}
auto it = lower_bound(h[cnt][a].begin(), h[cnt][a].end(), d);
if (it == h[cnt][a].end()) {
ans = 0;
break;
}
int v = *it;
//check if pattern doesn't cross the segment [l:r]
if ((v+cnt) > r) {
ans = 0;
break;
}
d = v+1;
i = j-1;
}
if (ans) {
printf("Yes\n");
}
else {
printf("No\n");
}
}
return 0;
}
LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoqICAgIEFVVEhPUjogICAgICAgICBCSFVWTkVTSCBKQUlOICAgICAgICAqCiogICAgSU5TVElUVUlUSU9OOiAgIEJJVFMgUElMQU5JLCBQSUxBTkkgICoKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAp0eXBlZGVmIGxvbmcgbG9uZyBMTDsgCnR5cGVkZWYgbG9uZyBkb3VibGUgTEQ7CnR5cGVkZWYgcGFpcjxpbnQsaW50PiBwaWk7Cgpjb25zdCBpbnQgTUFYID0gMWU1ICsgNTsKY29uc3QgaW50IExJTSA9IDUwOwpjb25zdCBsb25nIGxvbmcgcDEgPSAzMTsKY29uc3QgbG9uZyBsb25nIG1vZCA9IDk5OTk5OTkzNzsKCmludCBuOwpzdHJpbmcgcywgcDsKbWFwPGludCx2ZWN0b3I8aW50Pj4gaFtMSU1dOwoKaW50IG1haW4oKSB7CgkjaWZuZGVmIE9OTElORV9KVURHRQoJCS8vIGZyZW9wZW4oImlucC50eHQiLCAiciIsIHN0ZGluKTsKCSNlbmRpZgoJaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CgljaW4gPj4gczsKCW4gPSBzLmxlbmd0aCgpOwoJaW50IHEsIGwsIHIsIG07CglpbnQgYSwgYiwgYywgZDsKCWZvcihpbnQgaSA9IDA7IGkgPC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