#include <bits/stdc++.h>
using namespace std;

#define sz(v)               ((int)v.size())
#define ll                  long long
#define all(v)              (v.begin()) , (v.end())
#define rall(v)             (v.rbegin()) , (v.rend())

struct edge{
    int to, cap, flow, rev;
    edge(int _to, int _cap, int _flow, int _rev){
        to = _to, cap = _cap, flow = _flow, rev = _rev;
    }
};

struct Dinic{
    vector <edge> adj[105];
    int level[105], start[105], color[105];
    int sink, src;

    Dinic(int s, int t){
        src = s;
        sink = t;
        memset(start, 0, sizeof(start));
        memset(color, -1, sizeof color);
    }

    void addEdge(int from, int to, int cap1, int cap2)
    {
        // from -> to has cap1
        // to -> from has cap2
        edge e1 = edge(to, cap1, 0, adj[to].size() );
        edge e2 = edge(from, cap2, 0, adj[from].size() );

        adj[from].push_back(e1);
        adj[to].push_back(e2);
    }
    bool bfs()
    {
        memset(level, -1, sizeof(level));
        level[src] = 0;
        queue <int> q;
        q.push(src);

        while(!q.empty()){
            int cur = q.front();
            q.pop();

            for(edge &e : adj[cur]){
                if(level[e.to] == -1 && e.flow < e.cap){
                    level[e.to] = level[cur] + 1;
                    q.push(e.to);
                }
            }
        }
        return level[sink] != -1;
    }

    int sendFlow(int u, int flow)
    {
        if(u == sink)
            return flow;

        for( ;start[u] < sz(adj[u]);start[u]++){
            edge &e = adj[u][start[u]];

            if(level[e.to] == level[u] + 1 && e.flow < e.cap){
                int curflow = min(flow, e.cap - e.flow);

                curflow = sendFlow(e.to, curflow);

                if(curflow > 0){
                    e.flow += curflow;
                    adj[e.to][e.rev].flow -= curflow;
                    return curflow;
                }
            }
        }
        return 0;
    }

    int maxFlow()
    {
        if(src == sink)
            return 0;

        int totalflow = 0;

        while(bfs()){
            memset(start, 0, sizeof(start));
            int flow;
            while( (flow = sendFlow(src, INT_MAX)))
                totalflow += flow;
        }
        return totalflow;
    }

    void dfs(int node)
    {
        color[node] = 1;
        for(edge &e : adj[node])
            if(e.flow < e.cap && color[e.to] == -1)
                dfs(e.to);
    }

};

const double eps = 1e-12;

int n, m, x;
int u[505], v[505], c[505];
vector <int> minCuts;

bool valid(double a)
{
    int cnt = 0;
    for(int i = 0; i < sz(minCuts); i++){
        int t = 1.0 * minCuts[i] / a + eps;
        cnt += t;
    }
    return cnt >= x;
}
int main ()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d%d", &n, &m, &x);
    Dinic dinic(1, n);
    for(int i = 0; i < m; i++){
        scanf("%d%d%d", u + i, v + i, c + i);
        dinic.addEdge(u[i], v[i], c[i], 0);
    }
    dinic.maxFlow();
    dinic.dfs(1);

    for(int i = 0; i < m; i++){
        if(dinic.color[u[i]] * dinic.color[v[i]] == -1){
            minCuts.push_back(c[i]);
            //printf("%d %d\n", u[i], v[i]);
        }
    }

    double L = 0, R = 1e10;

    for(int i = 0; i < 300; i++){
        double mid = (L + R) / 2;
        if(valid(mid))
            L = mid;
        else
            R = mid;
    }
    printf("%.10f\n", x * L);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(v)               ((int)v.size())
#define ll                  long long
#define all(v)              (v.begin()) , (v.end())
#define rall(v)             (v.rbegin()) , (v.rend())

struct edge{
    int to, cap, flow, rev;
    edge(int _to, int _cap, int _flow, int _rev){
        to = _to, cap = _cap, flow = _flow, rev = _rev;
    }
};

struct Dinic{
    vector <edge> adj[105];
    int level[105], start[105], color[105];
    int sink, src;

    Dinic(int s, int t){
        src = s;
        sink = t;
        memset(start, 0, sizeof(start));
        memset(color, -1, sizeof color);
    }

    void addEdge(int from, int to, int cap1, int cap2)
    {
        // from -> to has cap1
        // to -> from has cap2
        edge e1 = edge(to, cap1, 0, adj[to].size() );
        edge e2 = edge(from, cap2, 0, adj[from].size() );

        adj[from].push_back(e1);
        adj[to].push_back(e2);
    }
    bool bfs()
    {
        memset(level, -1, sizeof(level));
        level[src] = 0;
        queue <int> q;
        q.push(src);

        while(!q.empty()){
            int cur = q.front();
            q.pop();

            for(edge &e : adj[cur]){
                if(level[e.to] == -1 && e.flow < e.cap){
                    level[e.to] = level[cur] + 1;
                    q.push(e.to);
                }
            }
        }
        return level[sink] != -1;
    }

    int sendFlow(int u, int flow)
    {
        if(u == sink)
            return flow;

        for( ;start[u] < sz(adj[u]);start[u]++){
            edge &e = adj[u][start[u]];

            if(level[e.to] == level[u] + 1 && e.flow < e.cap){
                int curflow = min(flow, e.cap - e.flow);

                curflow = sendFlow(e.to, curflow);

                if(curflow > 0){
                    e.flow += curflow;
                    adj[e.to][e.rev].flow -= curflow;
                    return curflow;
                }
            }
        }
        return 0;
    }

    int maxFlow()
    {
        if(src == sink)
            return 0;

        int totalflow = 0;

        while(bfs()){
            memset(start, 0, sizeof(start));
            int flow;
            while( (flow = sendFlow(src, INT_MAX)))
                totalflow += flow;
        }
        return totalflow;
    }

    void dfs(int node)
    {
        color[node] = 1;
        for(edge &e : adj[node])
            if(e.flow < e.cap && color[e.to] == -1 && e.flow > 0)
                dfs(e.to);
    }

};

const double eps = 1e-12;

int n, m, x;
int u[505], v[505], c[505];
vector <int> minCuts;

bool valid(double a)
{
    int cnt = 0;
    for(int i = 0; i < sz(minCuts); i++){
        int t = 1.0 * minCuts[i] / a;
        cnt += t;
    }
    return cnt >= x;
}
int main ()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d%d", &n, &m, &x);
    Dinic dinic(1, n);
    for(int i = 0; i < m; i++){
        scanf("%d%d%d", u + i, v + i, c + i);
        dinic.addEdge(u[i], v[i], c[i], 0);
    }
    dinic.maxFlow();
    dinic.dfs(1);

    for(int i = 0; i < m; i++){
        if(dinic.color[u[i]] * dinic.color[v[i]] == -1){
            minCuts.push_back(c[i]);
            //printf("%d %d\n", u[i], v[i]);
        }
    }

    double L = 0, R = 1e10;

    for(int i = 0; i < 300; i++){
        double mid = (L + R) / 2;
        if(valid(mid))
            L = mid;
        else
            R = mid;
    }
    printf("%.10f\n", x * L);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(v)               ((int)v.size())
#define ll                  long long
#define all(v)              (v.begin()) , (v.end())
#define rall(v)             (v.rbegin()) , (v.rend())

struct edge{
    int to, cap, flow, rev;
    edge(int _to, int _cap, int _flow, int _rev){
        to = _to, cap = _cap, flow = _flow, rev = _rev;
    }
};

struct Dinic{
    vector <edge> adj[105];
    int level[105], start[105], color[105];
    int sink, src;

    Dinic(int s, int t){
        src = s;
        sink = t;
        memset(start, 0, sizeof(start));
    }

    void addEdge(int from, int to, int cap1, int cap2)
    {
        // from -> to has cap1
        // to -> from has cap2
        edge e1 = edge(to, cap1, 0, adj[to].size() );
        edge e2 = edge(from, cap2, 0, adj[from].size() );

        adj[from].push_back(e1);
        adj[to].push_back(e2);
    }
    bool bfs()
    {
        memset(level, -1, sizeof(level));
        level[src] = 0;
        queue <int> q;
        q.push(src);

        while(!q.empty()){
            int cur = q.front();
            q.pop();

            for(edge &e : adj[cur]){
                if(level[e.to] == -1 && e.flow < e.cap){
                    level[e.to] = level[cur] + 1;
                    q.push(e.to);
                }
            }
        }
        return level[sink] != -1;
    }

    int sendFlow(int u, int flow)
    {
        if(u == sink)
            return flow;

        for( ;start[u] < sz(adj[u]);start[u]++){
            edge &e = adj[u][start[u]];

            if(level[e.to] == level[u] + 1 && e.flow < e.cap){
                int curflow = min(flow, e.cap - e.flow);

                curflow = sendFlow(e.to, curflow);

                if(curflow > 0){
                    e.flow += curflow;
                    adj[e.to][e.rev].flow -= curflow;
                    return curflow;
                }
            }
        }
        return 0;
    }

    int maxFlow()
    {
        if(src == sink)
            return 0;

        int totalflow = 0;

        while(bfs()){
            memset(start, 0, sizeof(start));
            int flow;
            while( (flow = sendFlow(src, INT_MAX)))
                totalflow += flow;
        }
        return totalflow;
    }
};

const double eps = 1e-12;

int n, m, x;
int u[505], v[505], c[505];

bool valid(double a)
{
    Dinic dinic(1, n);
    for(int i = 0; i < m; i++)
        dinic.addEdge(u[i], v[i], c[i] / a, 0);

    return dinic.maxFlow() >= x;
}
int main ()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d%d", &n, &m, &x);
    Dinic dinic(1, n);
    for(int i = 0; i < m; i++)
        scanf("%d%d%d", u + i, v + i, c + i);

    double L = 0, R = 1e10;

    for(int i = 0; i < 300; i++){
        double mid = (L + R) / 2;
        if(valid(mid))
            L = mid;
        else
            R = mid;
    }
    printf("%.10f\n", x * L);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(v)               ((int)v.size())
#define ll                  long long
#define all(v)              (v.begin()) , (v.end())
#define rall(v)             (v.rbegin()) , (v.rend())

struct edge{
    int to, cap, flow, rev;
    edge(int _to, int _cap, int _flow, int _rev){
        to = _to, cap = _cap, flow = _flow, rev = _rev;
    }
};

struct Dinic{
    vector <edge> adj[105];
    int level[105], start[105], color[105];
    int sink, src;

    Dinic(int s, int t){
        src = s;
        sink = t;
        memset(start, 0, sizeof(start));
        memset(color, -1, sizeof color);
    }

    void addEdge(int from, int to, int cap1, int cap2)
    {
        // from -> to has cap1
        // to -> from has cap2
        edge e1 = edge(to, cap1, 0, adj[to].size() );
        edge e2 = edge(from, cap2, 0, adj[from].size() );

        adj[from].push_back(e1);
        adj[to].push_back(e2);
    }
    bool bfs()
    {
        memset(level, -1, sizeof(level));
        level[src] = 0;
        queue <int> q;
        q.push(src);

        while(!q.empty()){
            int cur = q.front();
            q.pop();

            for(edge &e : adj[cur]){
                if(level[e.to] == -1 && e.flow < e.cap){
                    level[e.to] = level[cur] + 1;
                    q.push(e.to);
                }
            }
        }
        return level[sink] != -1;
    }

    int sendFlow(int u, int flow)
    {
        if(u == sink)
            return flow;

        for( ;start[u] < sz(adj[u]);start[u]++){
            edge &e = adj[u][start[u]];

            if(level[e.to] == level[u] + 1 && e.flow < e.cap){
                int curflow = min(flow, e.cap - e.flow);

                curflow = sendFlow(e.to, curflow);

                if(curflow > 0){
                    e.flow += curflow;
                    adj[e.to][e.rev].flow -= curflow;
                    return curflow;
                }
            }
        }
        return 0;
    }

    int maxFlow()
    {
        if(src == sink)
            return 0;

        int totalflow = 0;

        while(bfs()){
            memset(start, 0, sizeof(start));
            int flow;
            while( (flow = sendFlow(src, INT_MAX)))
                totalflow += flow;
        }
        return totalflow;
    }

    void dfs(int node)
    {
        color[node] = 1;
        for(edge &e : adj[node])
            if(e.flow < e.cap && color[e.to] == -1 && e.flow >= 0)
                dfs(e.to);
    }

};

const double eps = 1e-12;

int n, m, x;
int u[505], v[505], c[505];
vector <int> minCuts;

bool valid(double a)
{
    int cnt = 0;
    for(int i = 0; i < sz(minCuts); i++){
        int t = 1.0 * minCuts[i] / a;
        cnt += t;
    }
    return cnt >= x;
}
int main ()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d%d", &n, &m, &x);
    Dinic dinic(1, n);
    for(int i = 0; i < m; i++){
        scanf("%d%d%d", u + i, v + i, c + i);
        dinic.addEdge(u[i], v[i], c[i], 0);
    }
    dinic.maxFlow();
    dinic.dfs(1);

    for(int i = 0; i < m; i++){
        if(dinic.color[u[i]] * dinic.color[v[i]] == -1){
            minCuts.push_back(c[i]);
            //printf("%d %d\n", u[i], v[i]);
        }
    }

    double L = 0, R = 1e10;

    for(int i = 0; i < 300; i++){
        double mid = (L + R) / 2;
        if(valid(mid))
            L = mid;
        else
            R = mid;
    }
    printf("%.10f\n", x * L);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
double eps = 1e-12;
struct Edge {
	int from, to, cap, flow, index;
	Edge(int from, int to, int cap, int flow, int index) :
		from(from), to(to), cap(cap), flow(flow), index(index) {}
	LL rcap() { return cap - flow; }
};

struct Dinic {
	int N;
	vector<vector<Edge> > G;
	vector<vector<Edge *> > Lf;
	vector<int> layer;
	vector<int> Q;

	Dinic(int N) : N(N), G(N), Q(N) {}

	void AddEdge(int from, int to, int cap) {
		if (from == to) return;
		G[from].push_back(Edge(from, to, cap, 0, G[to].size()));
		G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));
	}

	LL BlockingFlow(int s, int t) {
		layer.clear(); layer.resize(N, -1);
		layer[s] = 0;
		Lf.clear(); Lf.resize(N);

		int head = 0, tail = 0;
		Q[tail++] = s;
		while (head < tail) {
			int x = Q[head++];
			for (int i = 0; i < G[x].size(); i++) {
				Edge &e = G[x][i]; if (e.rcap() <= 0) continue;
				if (layer[e.to] == -1) {
					layer[e.to] = layer[e.from] + 1;
					Q[tail++] = e.to;
				}
				if (layer[e.to] > layer[e.from]) {
					Lf[e.from].push_back(&e);
				}
			}
		}
		if (layer[t] == -1) return 0;

		LL totflow = 0;
		vector<Edge *> P;
		while (!Lf[s].empty()) {
			int curr = P.empty() ? s : P.back()->to;
			if (curr == t) { // Augment
				LL amt = P.front()->rcap();
				for (int i = 0; i < P.size(); ++i) {
					amt = min(amt, P[i]->rcap());
				}
				totflow += amt;
				for (int i = P.size() - 1; i >= 0; --i) {
					P[i]->flow += amt;
					G[P[i]->to][P[i]->index].flow -= amt;
					if (P[i]->rcap() <= 0) {
						Lf[P[i]->from].pop_back();
						P.resize(i);
					}
				}
			}
			else if (Lf[curr].empty()) { // Retreat
				P.pop_back();
				for (int i = 0; i < N; ++i)
				for (int j = 0; j < Lf[i].size(); ++j)
				if (Lf[i][j]->to == curr)
					Lf[i].erase(Lf[i].begin() + j);
			}
			else { // Advance
				P.push_back(Lf[curr].back());
			}
		}
		return totflow;
	}

	LL GetMaxFlow(int s, int t) {
		LL totflow = 0;
		while (LL flow = BlockingFlow(s, t))
			totflow += flow;
		return totflow;
	}
};

pair<int,pair<int,int> > ed[505];

int n,m,x;
int cnt = 0;

bool ch(double mid , Dinic &g)
{
    for (int i=0;i<m;i++)
    {
        int x , y;
        double c;
        x = ed[i].first;
        y = ed[i].second.first;
        c = ed[i].second.second * 1.0 / mid;
        g.AddEdge(x , y , (int)c);
    }
    LL ret = g.GetMaxFlow(1 , n);
    return ret >= x;

}

double bs(double l,double h)
{
    double mid = (l + h) / 2;
    if (cnt > 200)return mid;
    Dinic g(n + 5);
    if (ch(mid , g) && !ch(mid + eps , g))return mid;
    if (ch(mid , g))return bs(mid + eps , h);
    return bs(l,mid - eps);

}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> m >> x;
    for (int i=0;i<m;i++)
    {
        int x,y,c;
        cin >> x >> y >> c;
        ed[i].first = x;
        ed[i].second.first = y;
        ed[i].second.second = c;
    }
    double ans = bs(0,1000000);
    ans *= x;
    cout << fixed << setprecision(7) << ans << endl;
   // cout << "Hello world!" << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
double eps = 1e-12;
struct Edge
{
    int from, to, cap, flow, index;
    Edge(int from, int to, int cap, int flow, int index) :
        from(from), to(to), cap(cap), flow(flow), index(index) {}
    LL rcap()
    {
        return cap - flow;
    }
};

struct Dinic
{
    int N;
    vector<vector<Edge> > G;
    vector<vector<Edge *> > Lf;
    vector<int> layer;
    vector<int> Q;

    Dinic(int N) : N(N), G(N), Q(N) {}

    void AddEdge(int from, int to, int cap)
    {
        if (from == to)
            return;
        G[from].push_back(Edge(from, to, cap, 0, G[to].size()));
        G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));
    }

    LL BlockingFlow(int s, int t)
    {
        layer.clear();
        layer.resize(N, -1);
        layer[s] = 0;
        Lf.clear();
        Lf.resize(N);

        int head = 0, tail = 0;
        Q[tail++] = s;
        while (head < tail)
        {
            int x = Q[head++];
            for (int i = 0; i < G[x].size(); i++)
            {
                Edge &e = G[x][i];
                if (e.rcap() <= 0)
                    continue;
                if (layer[e.to] == -1)
                {
                    layer[e.to] = layer[e.from] + 1;
                    Q[tail++] = e.to;
                }
                if (layer[e.to] > layer[e.from])
                {
                    Lf[e.from].push_back(&e);
                }
            }
        }
        if (layer[t] == -1)
            return 0;

        LL totflow = 0;
        vector<Edge *> P;
        while (!Lf[s].empty())
        {
            int curr = P.empty() ? s : P.back()->to;
            if (curr == t)   // Augment
            {
                LL amt = P.front()->rcap();
                for (int i = 0; i < P.size(); ++i)
                {
                    amt = min(amt, P[i]->rcap());
                }
                totflow += amt;
                for (int i = P.size() - 1; i >= 0; --i)
                {
                    P[i]->flow += amt;
                    G[P[i]->to][P[i]->index].flow -= amt;
                    if (P[i]->rcap() <= 0)
                    {
                        Lf[P[i]->from].pop_back();
                        P.resize(i);
                    }
                }
            }
            else if (Lf[curr].empty())   // Retreat
            {
                P.pop_back();
                for (int i = 0; i < N; ++i)
                    for (int j = 0; j < Lf[i].size(); ++j)
                        if (Lf[i][j]->to == curr)
                            Lf[i].erase(Lf[i].begin() + j);
            }
            else   // Advance
            {
                P.push_back(Lf[curr].back());
            }
        }
        return totflow;
    }

    LL GetMaxFlow(int s, int t)
    {
        LL totflow = 0;
        while (LL flow = BlockingFlow(s, t))
            totflow += flow;
        return totflow;
    }
};

pair<int,pair<int,int> > ed[505];

int n,m,x;
int cnt = 0;

bool ch(double mid)
{
    Dinic g(n + 5);
    for (int i=0; i<m; i++)
    {
        int x, y;
        double c;
        x = ed[i].first;
        y = ed[i].second.first;
        c = ed[i].second.second * 1.0 / mid;
        g.AddEdge(x, y, min((LL)c , 100000LL));
    }

    LL ret = g.GetMaxFlow(1, n);
    return ret >= x;

}

double bs(double l,double h)
{
    cnt++;
    double mid = (l + h) / 2;
    if (cnt > 80)
        return mid;
    if (ch(mid) && !ch(mid + eps))
        return mid;
    if (ch(mid))
    {
        return bs(mid + eps, h);
    }
    return bs(l,mid - eps);

}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> m >> x;
    for (int i=0; i<m; i++)
    {
        int x,y,c;
        cin >> x >> y >> c;
        ed[i].first = x;
        ed[i].second.first = y;
        ed[i].second.second = c;
    }
    double ans = bs(0,1000000);
    ans *= x;
    cout << fixed << setprecision(7) << ans << endl;
    // cout << "Hello world!" << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
double eps = 1e-8;
struct Edge {
	int from, to, cap, flow, index;
	Edge(int from, int to, int cap, int flow, int index) :
		from(from), to(to), cap(cap), flow(flow), index(index) {}
	LL rcap() { return cap - flow; }
};

struct Dinic {
	int N;
	vector<vector<Edge> > G;
	vector<vector<Edge *> > Lf;
	vector<int> layer;
	vector<int> Q;

	Dinic(int N) : N(N), G(N), Q(N) {}

	void AddEdge(int from, int to, int cap) {
		if (from == to) return;
		G[from].push_back(Edge(from, to, cap, 0, G[to].size()));
		G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));
	}

	LL BlockingFlow(int s, int t) {
		layer.clear(); layer.resize(N, -1);
		layer[s] = 0;
		Lf.clear(); Lf.resize(N);

		int head = 0, tail = 0;
		Q[tail++] = s;
		while (head < tail) {
			int x = Q[head++];
			for (int i = 0; i < G[x].size(); i++) {
				Edge &e = G[x][i]; if (e.rcap() <= 0) continue;
				if (layer[e.to] == -1) {
					layer[e.to] = layer[e.from] + 1;
					Q[tail++] = e.to;
				}
				if (layer[e.to] > layer[e.from]) {
					Lf[e.from].push_back(&e);
				}
			}
		}
		if (layer[t] == -1) return 0;

		LL totflow = 0;
		vector<Edge *> P;
		while (!Lf[s].empty()) {
			int curr = P.empty() ? s : P.back()->to;
			if (curr == t) { // Augment
				LL amt = P.front()->rcap();
				for (int i = 0; i < P.size(); ++i) {
					amt = min(amt, P[i]->rcap());
				}
				totflow += amt;
				for (int i = P.size() - 1; i >= 0; --i) {
					P[i]->flow += amt;
					G[P[i]->to][P[i]->index].flow -= amt;
					if (P[i]->rcap() <= 0) {
						Lf[P[i]->from].pop_back();
						P.resize(i);
					}
				}
			}
			else if (Lf[curr].empty()) { // Retreat
				P.pop_back();
				for (int i = 0; i < N; ++i)
				for (int j = 0; j < Lf[i].size(); ++j)
				if (Lf[i][j]->to == curr)
					Lf[i].erase(Lf[i].begin() + j);
			}
			else { // Advance
				P.push_back(Lf[curr].back());
			}
		}
		return totflow;
	}

	LL GetMaxFlow(int s, int t) {
		LL totflow = 0;
		while (LL flow = BlockingFlow(s, t))
			totflow += flow;
		return totflow;
	}
};

pair<int,pair<int,int> > ed[505];

int n,m,x;
int cnt = 0;

bool ch(double mid , Dinic &g)
{
    for (int i=0;i<m;i++)
    {
        int x , y;
        double c;
        x = ed[i].first;
        y = ed[i].second.first;
        c = ed[i].second.second * 1.0 / mid;
        g.AddEdge(x , y , (int)c);
    }
    LL ret = g.GetMaxFlow(1 , n);
    return ret >= x;

}

double bs(double l,double h)
{
    double mid = (l + h) / 2;
    if (cnt > 200)return mid;
    Dinic g(n + 5);
    if (ch(mid , g) && !ch(mid + eps , g))return mid;
    if (ch(mid , g))return bs(mid + eps , h);
    return bs(l,mid - eps);

}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> m >> x;
    for (int i=0;i<m;i++)
    {
        int x,y,c;
        cin >> x >> y >> c;
        ed[i].first = x;
        ed[i].second.first = y;
        ed[i].second.second = c;
    }
    double ans = bs(0,1000000);
    ans *= x;
    cout << fixed << setprecision(7) << ans << endl;
   // cout << "Hello world!" << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

const int mx = 100100;

int main() {
    string a,b,c;
    int n,arr[27] = {},p;
    bool cek;
    cin >> a >> b;
    repi(0,a.length(),1) arr[a[i]-'a'] = 1;
    scd(n);
    repi(0,n,1) {
        cin >> c;
        cek = true;
        p = 0;
        repi(0,b.length(),1) {
            if(b[i] == '?') {
                if(arr[c[p]-'a'] == 0) {
                    cek = false;
                    break;
                }
                p++;
            }
            else if(b[i] == '*') {
                while(p < c.length()) {
                    if(arr[c[p]-'a'] == 0) p++;
                    else break;
                }
            }
            else {
                if(b[i] != c[p]) {
                    cek = false;
                    break;
                }
                p++;
            }
        }
        //out << p << " " << c.length() << endl;
        if(p < c.length()) cek = false;
        printf("%s",(cek ? "YES\n" : "NO\n"));
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

const int mx = 100100;

int main() {
    string a,b,c;
    int n,arr[27] = {},p;
    bool cek;
    cin >> a >> b;
    repi(0,a.length(),1) arr[a[i]-'a'] = 1;
    scd(n);
    repi(0,n,1) {
        cin >> c;
        cek = true;
        p = 0;
        repi(0,b.length(),1) {
            if(b[i] == '?') {
                if(arr[c[i]-'a'] == 0) {
                    cek = false;
                    break;
                }
                p++;
            }
            else if(b[i] == '*') {
                while(p < c.length()) {
                    if(arr[c[p]-'a'] == 0) p++;
                    else break;
                }
            }
            else {
                if(b[i] != c[i]) {
                    cek = false;
                    break;
                }
                p++;
            }
        }
        //out << p << " " << c.length() << endl;
        if(p < c.length()) cek = false;
        printf("%s",(cek ? "YES\n" : "NO\n"));
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

const int mx = 100100;

int main() {
    string a,b,c;
    int n,arr[27] = {},p;
    bool cek;
    cin >> a >> b;
    repi(0,a.length(),1) arr[a[i]-'a'] = 1;
    scd(n);
    repi(0,n,1) {
        cin >> c;
        cek = true;
        p = 0;
        repi(0,b.length(),1) {
            if(b[i] == '?') {
                if(arr[c[p]-'a'] == 0) {
                    //cout << "B\n";
                    cek = false;
                    break;
                }
                p++;
            }
            else if(b[i] == '*') {
                while(c.length()-p != b.length()-i-1) {
                    if(arr[c[p]-'a']) {
                        cek = false;
                        break;
                    }
                    p++;
                }
                //cout << p << endl;
            }
            else {
                if(b[i] != c[p]) {
                    //cout << i << " " << p << endl;
                    //cout << "D\n";
                    cek = false;
                    break;
                }
                p++;
            }
        }
        if(p < c.length() || c.length() < b.length()) cek = false;
        printf("%s",(cek ? "YES\n" : "NO\n"));
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

const int mx = 100100;

int main() {
    string a,b,c;
    int n,arr[27] = {},p;
    bool cek;
    cin >> a >> b;
    repi(0,a.length(),1) arr[a[i]-'a'] = 1;
    scd(n);
    repi(0,n,1) {
        cin >> c;
        cek = true;
        p = 0;
        repi(0,b.length(),1) {
            if(b[i] == '?') {
                if(p >= c.length()) {
                    //cout << "A\n";
                    cek = false;
                    break;
                }
                if(arr[c[p]-'a'] == 0) {
                    //cout << "B\n";
                    cek = false;
                    break;
                }
                p++;
            }
            else if(b[i] == '*') {
                while(p < c.length()) {
                    if(arr[c[p]-'a'] == 0) p++;
                    else break;
                    if(c.length()-p+1 == b.length()-i) break;
                }
                //cout << p << endl;
            }
            else {
                if(p >= c.length()) {
                    //cout << "C\n";
                    cek = false;
                    break;
                }
                if(b[i] != c[p]) {
                    //cout << i << " " << p << endl;
                    //cout << "D\n";
                    cek = false;
                    break;
                }
                p++;
            }
        }
        if(p < c.length()) cek = false;
        printf("%s",(cek ? "YES\n" : "NO\n"));
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

const int mx = 100100;

int main() {
    string a,b,c;
    int n,arr[27] = {},p;
    bool cek;
    cin >> a >> b;
    repi(0,a.length(),1) arr[a[i]-'a'] = 1;
    scd(n);
    repi(0,n,1) {
        cin >> c;
        cek = true;
        p = 0;
        repi(0,b.length(),1) {
            if(b[i] == '?') {
                if(arr[c[p]-'a'] == 0) {
                    //cout << "B\n";
                    cek = false;
                    break;
                }
                p++;
            }
            else if(b[i] == '*') {
                while(c.length()-p != b.length()-i-1) {
                    if(arr[c[p]-'a']) {
                        cek = false;
                        break;
                    }
                    p++;
                }
                //cout << p << endl;
            }
            else {
                if(b[i] != c[p]) {
                    //cout << i << " " << p << endl;
                    //cout << "D\n";
                    cek = false;
                    break;
                }
                p++;
            }
        }
        cout << p << endl;
        if(p != c.length()) cek = false;
        printf("%s",(cek ? "YES\n" : "NO\n"));
    }
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=100000+999;
char a[maxn],b[maxn];
bool pd[30];
char c[30];
int len1,len2,len3,n;
int flag;
int left;
bool judge(){
	if(flag){
		for(int i=0;i<flag;i++){
			if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
			else {return 0;}  }
		int i=len2-1,j=len1-1;
		while(a[j]!='*'){
			if(b[i]==a[j]||(a[i]=='?'&&pd[b[i]-'a']))i--,j--;
			else {return 0;}
			}
		for(j;j<i;j++)if(pd[b[j]-'a'])return 0;
		return 1;
		}
	if(len2!=len1)return 0;
	for(int i=0;i<len1;i++){
	if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
	else return 0;}
	return 1;
}
int main(){
	cin>>c;
	cin>>a;
	len3=strlen(c);len1=strlen(a);
	for(int i=0;i<len3;i++)pd[c[i]-'a']=1;
	for(int i=0;i<len1;i++)if(a[i]=='*')flag=i;
	cin>>n;
	while(n){n--;
		cin>>b;
		len2=strlen(b);
		if(judge())cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=100000+999;
char a[maxn],b[maxn];
bool pd[30];
char c[30];
int len1,len2,len3,n;
int flag;
int left;
bool judge(){
	if(flag){
		for(int i=0;i<flag-1;i++){
			if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
			else {return 0;}  }
		int j=len1-1,i=len2-1;
		while(a[j]!='*'){
			if(b[i]==a[j]||(a[j]=='?'&&pd[b[i]-'a']))i--,j--;
			else {return 0;}
			}
		for(j=flag-1;j<=i;j++){if(pd[b[j]-'a']){return 0;}}
		return 1;
		}
	if(len2!=len1)return 0;
	for(int i=0;i<=len1;i++){
	if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
	else return 0;}
	return 1;
}
int main(){
	cin>>c;
	cin>>a;
	len3=strlen(c);len1=strlen(a);
	for(int i=0;i<len3;i++)pd[c[i]-'a']=1;
	for(int i=0;i<len1;i++)if(a[i]=='*')flag=i+1;
	cin>>n;
	while(n){n--;
		cin>>b;
		len2=strlen(b);
		if(judge())cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=100000+999;
char a[maxn],b[maxn];
bool pd[30];
char c[30];
int len1,len2,len3,n;
int flag;
int left;
bool judge(){
	if(flag){
		for(int i=0;i<flag;i++){
			if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
			else {return 0;}  }
		int i=len2,j=len1;
		while(a[j]!='*'){
			if(b[i]==a[j]||(a[i]=='?'&&pd[b[i]-'a']))i--,j--;
			else {return 0;}
			}
		for(j;j<i;j++)if(pd[b[j]-'a'])return 0;
		return 1;
		}
	if(len2!=len1)return 0;
	for(int i=0;i<=len1;i++){
	if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
	else return 0;}
	return 1;
}
int main(){
	cin>>c;
	cin>>a;
	len3=strlen(c);len1=strlen(a);
	for(int i=0;i<len3;i++)pd[c[i]-'a']=1;
	for(int i=0;i<len1;i++)if(a[i]=='*')flag=i;
	cin>>n;
	while(n){n--;
		cin>>b;
		len2=strlen(b);
		if(judge())cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=10005;
bool bm[30];
char a[30],str1[N],str2[N];
int len1,len2,n;
bool match()
{
	int i=1,j=1,left,right;
	while(i<len1&&j<len2)
	{
		if(str1[i]==str2[j])++i,++j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else ++i,++j;
          }
          else if(str1[i]=='*'){left=j;break;}
          else return false;
		}
	}
	if(i==len1&&j==len2)return true;
	i=len1,j=len2;
	while(i>=0&&j>=0)
	{
		if(str1[i]==str2[j])--i,--j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else --i,--j;
          }
          else if(str1[i]=='*'){right=j;break;}
		}
	}
	for(i=left;i<=right;++i)
	  if(bm[str2[i]-'a']==true)return false;
	return true;
}
int main()
{
    cin>>a;
    int la=strlen(a);
    for(int i=0;i<la;++i)
    {
      int j=a[i]-'a';
      bm[j]=true;
    }
    cin>>str1>>n;
    len1=strlen(str1);
    for(int t=1;t<=n;++t)
    {
      memset(str2,0,sizeof(str2));
      cin>>str2;
      len2=strlen(str2);
      bool ok=match();
      if(ok)printf("YES\n");
      else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=100005;
bool bm[30];
char a[30],str1[N],str2[N];
int len1,len2,n;
bool match()
{
	int i=0,j=0,left,right;
	while(i<len1&&j<len2)
	{
		if(str1[i]==str2[j])++i,++j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else ++i,++j;
          }
          else if(str1[i]=='*'){left=j;break;}
          else return false;
		}
	}
	if(i==len1&&j==len2)return true;
	i=len1-1,j=len2-1;
	while(i>=0&&j>=0)
	{
		if(str1[i]==str2[j])--i,--j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else --i,--j;
          }
          else if(str1[i]=='*'){right=j;break;}
		}
	}
	for(i=left;i<=right;++i)
	  if(bm[str2[i]-'a']==true)return false;
	return true;
}
int main()
{
    cin>>a;
    int la=strlen(a);
    for(int i=0;i<la;++i)
    {
      int j=a[i]-'a';
      bm[j]=true;
    }
    cin>>str1>>n;
    len1=strlen(str1);
    for(int t=1;t<=n;++t)
    {
      memset(str2,0,sizeof(str2));
      cin>>str2;
      len2=strlen(str2);
      bool ok=match();
      if(ok)printf("YES\n");
      else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=100000+999;
char a[maxn],b[maxn];
bool pd[30];
char c[30];
int len1,len2,len3,n;
int flag;
int left;
bool judge(){
	if(flag){
		for(int i=0;i<flag-1;i++){
			if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
			else {return 0;}  }
		int i=len2-1,j=len1-1;
		while(a[j]!='*'){
			if(b[i]==a[j]||(a[i]=='?'&&pd[b[i]-'a']))i--,j--;
			else {return 0;}
			}
		for(j;j<=i;j++){if(pd[b[j]-'a']){return 0;}}
		return 1;
		}
	if(len2!=len1)return 0;
	for(int i=0;i<=len1;i++){
	if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
	else return 0;}
	return 1;
}
int main(){
	cin>>c;
	cin>>a;
	len3=strlen(c);len1=strlen(a);
	for(int i=0;i<len3;i++)pd[c[i]-'a']=1;
	for(int i=0;i<len1;i++)if(a[i]=='*')flag=i+1;
	cin>>n;
	while(n){n--;
		cin>>b;
		len2=strlen(b);
		if(judge())cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=100000+999;
char a[maxn],b[maxn];
bool pd[30];
char c[30];
int len1,len2,len3,n;
int flag;
int left;
bool judge(){
	if(flag){
        if(len1-1>len2)return 0;
		for(int i=0;i<flag-1;i++){
			if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
			else {return 0;}  }
		int j=len1-1,i=len2-1;
		while(a[j]!='*'){
			if(b[i]==a[j]||(a[j]=='?'&&pd[b[i]-'a']))i--,j--;
			else {return 0;}
			}
		for(j=flag-1;j<=i;j++){if(pd[b[j]-'a']){return 0;}}
		return 1;
		}
	if(len2!=len1)return 0;
	for(int i=0;i<=len1;i++){
	if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
	else return 0;}
	return 1;
}
int main(){
	cin>>c;
	cin>>a;
	len3=strlen(c);len1=strlen(a);
	for(int i=0;i<len3;i++)pd[c[i]-'a']=1;
	for(int i=0;i<len1;i++)if(a[i]=='*')flag=i+1;
	cin>>n;
	while(n){n--;
		cin>>b;
		len2=strlen(b);
		if(judge())cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=100005;
bool bm[30],star=false;;
char a[30],str1[N],str2[N];
int len1,len2,n,l,r;
bool match()
{
	int i=0,j;
    while(i<l)
	{
		if(str1[i]==str2[i] || str1[i]=='?'&&bm[str2[i]-'a'])
          ++i;
		else return false;
	}
 	if(star==false)
	{
	  if(len1==len2){return true;}
	  return false;
	}
	i=len1-1,j=len2-1;
	while(str1[i]!='*')
	if(str1[i]==str2[j] || str1[i]=='?'&&bm[str2[i]-'a'])
      --i,--j;
    r=j;
	for(i=l;i<=r;++i)
	  if(bm[str2[i]-'a']==true)return false;
	return true;
}
int main()
{
    cin>>a;
    int la=strlen(a);
    for(int i=0;i<la;++i)
    {
      int j=a[i]-'a';
      bm[j]=true;
    }
    scanf("%s\n",str1);
    cin>>n;
    len1=strlen(str1);
    int i=0;
    for(i=0;i<len1;++i)
      if(str1[i]=='*')
        {star=true;break;}
    l=i;
    for(int t=1;t<=n;++t)
    {
      memset(str2,0,sizeof(str2));
      scanf("\n%s",str2);
      len2=strlen(str2);
      if(match())printf("YES\n");
      else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=100005;
bool bm[30];
char a[30],str1[N],str2[N];
int len1,len2,n;
bool match()
{
	int i=0,j=0,left,right;
	bool star=false;
	while(i<len1)
	{
		if(str1[i]==str2[i])++i;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else ++i;
          }
          else if(str1[i]=='*'){left=i;star=true;break;}
          else return false;
		}
	}
	if(star==false)
	{
	  if(len1==len2){return true;}
	  return false;
	}
	i=len1-1,j=len2-1;
	while(i>=0&&j>=0)
	{
		if(str1[i]==str2[j])--i,--j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else --i,--j;
          }
          else if(str1[i]=='*'){right=j;break;}
		}
	}
	for(i=left;i<=right;++i)
	  if(bm[str2[i]-'a']==true)return false;
	return true;
}
int main()
{
    cin>>a;
    int la=strlen(a);
    for(int i=0;i<la;++i)
    {
      int j=a[i]-'a';
      bm[j]=true;
    }
    scanf("%s\n",str1);
    cin>>n;
    len1=strlen(str1);
    for(int t=1;t<=n;++t)
    {
      memset(str2,0,sizeof(str2));
      scanf("\n%s",str2);
      len2=strlen(str2);
      bool ok=match();
      if(ok)printf("YES\n");
      else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=100000+999;
char a[maxn],b[maxn];
bool pd[30];
char c[30];
int len1,len2,len3,n;
int flag;
int left;
bool judge(){
	if(flag){
		for(int i=0;i<flag;i++){
			if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
			else {return 0;}  }
		int i=len2,j=len1;
		while(a[j]!='*'){
			if(b[i]==a[j]||(a[i]=='?'&&pd[b[i]-'a']))i--,j--;
			else {return 0;}
			}
		for(j;j<i;j++)if(pd[b[j]-'a'])return 0;
		return 1;
		}
	if(len2!=len1)return 0;
	for(int i=0;i<=len1;i++){
	if(a[i]==b[i]||(a[i]=='?'&&pd[b[i]-'a']));
	else return 0;}
	return 1;
}
int main(){
	cin>>c;
	cin>>a;
	len3=strlen(c);len1=strlen(a);
	for(int i=0;i<=len3;i++)pd[c[i]-'a']=1;
	for(int i=0;i<len1;i++)if(a[i]=='*')flag=i;
	cin>>n;
	while(n){n--;
		cin>>b;
		len2=strlen(b);
		if(judge())cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=100005;
bool bm[30];
char a[30],str1[N],str2[N];
int len1,len2,n;
bool match()
{
	int i=0,j=0,left,right;
	bool star=false;
	while(i<len1)
	{
		if(str1[i]==str2[i])++i;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else ++i;
          }
          else if(str1[i]=='*'){left=i;star=true;break;}
          else return false;
		}
	}
	if(star==false)
	{
	  if(len1==len2){return true;}
	  return false;
	}
	i=len1-1,j=len2-1;
	while(i>=0&&j>=0)
	{
		if(str1[i]==str2[j])--i,--j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else --i,--j;
          }
          else if(str1[i]=='*'){right=j;break;}
		}
	}
	for(i=left;i<=right;++i)
	  if(bm[str2[i]-'a']==true)return false;
	return true;
}
int main()
{
    cin>>a;
    int la=strlen(a);
    for(int i=0;i<la;++i)
    {
      int j=a[i]-'a';
      bm[j]=true;
    }
    cin>>str1>>n;
    len1=strlen(str1);
    for(int t=1;t<=n;++t)
    {
      memset(str2,0,sizeof(str2));
      cin>>str2;
      len2=strlen(str2);
      bool ok=match();
      if(ok)printf("YES\n");
      else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=10005;
bool bm[30];
char a[30],str1[N],str2[N];
int len1,len2,n;
bool match()
{
	int i=0,j=0,left,right;
	while(i<len1&&j<len2)
	{
		if(str1[i]==str2[j])++i,++j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else ++i,++j;
          }
          else if(str1[i]=='*'){left=j;break;}
          else return false;
		}
	}
	if(i==len1&&j==len2)return true;
	i=len1-1,j=len2-1;
	while(i>=0&&j>=0)
	{
		if(str1[i]==str2[j])--i,--j;
		else
		{
		  if(str1[i]=='?')
		  {
            if(bm[str2[i]-'a']==false)return false;
            else --i,--j;
          }
          else if(str1[i]=='*'){right=j;break;}
		}
	}
	for(i=left;i<=right;++i)
	  if(bm[str2[i]-'a']==true)return false;
	return true;
}
int main()
{
    cin>>a;
    int la=strlen(a);
    for(int i=0;i<la;++i)
    {
      int j=a[i]-'a';
      bm[j]=true;
    }
    cin>>str1>>n;
    len1=strlen(str1);
    for(int t=1;t<=n;++t)
    {
      memset(str2,0,sizeof(str2));
      cin>>str2;
      len2=strlen(str2);
      bool ok=match();
      if(ok)printf("YES\n");
      else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e5 + 10;
string s,s1,s2;
int f[30];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			cout << s << ' ' << s1 << endl;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
 			if (s1.length()+1<s.length()) {
				cout << "NO" << endl;
				continue;
			}
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;

				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e5 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
 	int lens = s.length();
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		int lens1 = s1.length();
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
 			if (s1.length()+1<s.length()) {
				cout << "NO" << endl;
				continue;
			}
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+lens1-lens;i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;

				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
 			if (s1.length()+1<s.length()) {
				cout << "NO" << endl;
				continue;
			}
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,-2,sizeof(f));
	cin >> s;
    for (int i=1;i<=26;i++) {
    	f[(int)'a'+1] = 0;
	}
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
 			if (s1.length()+1<s.length()) {
				cout << "NO" << endl;
				continue;
			}
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
 			if (s1.length()+1<s.length()) {
				cout << "NO" << endl;
				continue;
			}
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					cout << "NO" << endl;
					continue;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e5 + 10;
string s,s1,s2;
int f[30];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
string s,s1,s2;
int f[5000];
int k;

int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	int pos = s.length();
	for (int i=0;i<s.length();i++) if (s[i]=='*') pos = i;
 	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s1;
		if (pos==s.length()) {
			if (s1.length()!=s.length()) {
				cout << "NO" << endl;
				continue;
			}
			bool flag = true;
			for (int i=0;i<s.length();i++) {
				if (s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
 			bool flag = true;
 			if (s1.length()+1<s.length()) {
				cout << "NO" << endl;
				continue;
			}
			for (int i=0;i<pos;i++) {
				if(s[i]!=s1[i] && (f[s1[i]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
		    if (!flag) {
		    	cout << "NO" << endl;
		    	continue;
			}
			for (int i=s.length()-1;i>pos;i--) {
				if (s[i]!=s1[i+s1.length()-s.length()] && (f[s1[i+s1.length()-s.length()]-'a'+1]==0 || s[i]!='?')) flag = false;
			}
			if (!flag) {
		        cout << "NO" << endl;
		    	continue;
			}
			for (int i=pos;i<=pos+s1.length()-s.length();i++) {
				if (f[s1[i]-'a'+1]==1) {
					flag = false;
					break;
				}
			}
			if (flag) cout << "YES" << endl;
			else cout << "NO" << endl;
 		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int MAXN = 1e5 + 10;
string s,s1,s2;
int f[30];
int k;

bool find(string a,string b) {
	int lena = a.length();
	int lenb = b.length();
	if (lena<lenb) return false;
	for (int i=0;i<=lena-lenb;i++) {
		bool flag = true;
		for (int j=0;j<lenb;j++) {
			if (a[i+j]==b[j] || (a[i+j]=='?' && f[b[j]-'a'+1]==1) || (a[i+j]=='*' && f[b[j]-'a'+1]==0)) continue;
			flag = false;
			break;
		}
		if (flag) return true;
	}
	return false;
}
int main()
{
	memset(f,0,sizeof(f));
	cin >> s;
	for (int i=0;i<s.length();i++) {
		f[s[i]-'a'+1] = 1;
	}
	cin >> s;
	s1="";
	s2="";
	for (int i=0;i<s.length();i++) {
		s1 = s1 + s[i];
		if (s[i]!='*') s2 = s2 + s[i];
	}
	cin >> k;
	for (int ii=1;ii<=k;ii++) {
		cin >> s;
		if (s.length()>s1.length()) {
			cout << "NO" << endl;
			continue;
		}
		bool flag = find(s1,s);
		if (flag) {
			cout << "YES" << endl;
			continue;
		}
		flag = find(s2,s);
		if (flag) {
			cout << "YES" << endl;
			continue;
		}
		cout << "NO" << endl;
	}
}


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    int z = 0;
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            z++;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        int x = 0;
        for(int i = 0 ; i < ll ; i++){
            int j = i;
            if(a[t[j]-'a']) continue;
            while(t[j]&&a[t[j]-'a']==0)
                j++;
            t[i] = '*';
            for(int k = j ; k < ll ; k++)
                t[i+k-j+1] = t[k];
            ll = ll-(j-i)+1;
            x++;
        }
        if(x>1)
            f = false;
        int i = 0;
        int j = 0;
        while(i < l){
            if(s[i]=='*') {i++;continue;}
            if(t[j]=='*') {j++;continue;}
            if(s[i]=='?'&&a[t[j]-'a']){
                i++;j++;
                continue;
            }
            if(s[i] != t[j])
                f = false;
            i++;
            j++;
        }
        if(t[j]=='*') {j++;}
        if(j != ll) f = false;
//        if(z){
//            if(l==ll){
//                for(int i = 0 ; f&&i < ll ; i++){
//                    if(s[i]=='?'&&a[t[i]-'a'])continue;
//                    if(s[i]!=t[i]) f = false;
//                }
//            }
//            else if(l == ll+1){
//                int j = 0;
//                for(int i = 0 ; i < l ; i++){
//                    if(s[i]=='*')continue;
//                    if(s[i]=='?'&&a[t[j]-'a']);
//                    else if(s[i]!=t[j])
//                        f = false;
//                    j++;
//                }
//            }
//            else f = false;
//        }
//        else {
//            if(l != ll)
//                f = false;
//            else{
//                for(int i = 0 ; f&&i < ll ; i++){
//                    if(s[i]=='?'&&a[t[i]-'a'])continue;
//                    if(s[i]!=t[i]) f = false;
//                }
//            }
//        }
        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


#include<bits/stdc++.h>
#define PB(u)  push_back(u)
#define AA   first
#define BB   second
#define inf 0x3f3f3f3f
using namespace std ;
#define MAX 100005
#define sz size()
typedef long long ll ;
typedef pair<int,int> PII ;
const double eps=1e-8;
const double pi=acos(-1.0);
const int mod=1e9+7;

char s[MAX],t[MAX];
int m[300];

int main()
{
    scanf(" %s %s",s,t);
    int len=strlen(s);
    for(int i=0; i<len; i++)
        m[s[i]-'a']=1;
    int n=strlen(t);
    int id = -1;
    for(int i=0; i<n; i++)
    {
        if(t[i]=='*')
        {
            id=i;
        }
    }
    int T;
    cin>>T;
    while(T--)
    {
        scanf("%s",s);
        int l=strlen(s);
        bool f = true;
        if(id>=0)
        {
            for(int i=0; i<id; i++)
            {
                if(s[i]==t[i]||(t[i]=='?'&&m[s[i]-'a'])) ;
                else f = false;
            }
            if(l<n-1) f = false;
            else
            {
                int x=l-1;
                for(int i=n-1; i>id ; x--,i--)
                {
                    if(s[x]==t[i]||(t[i]=='?'&&m[s[i]-'a'])) ;
                    else f = false;
                }
                if(x<id-1)
                    f = false;
                else
                    for(int i=id; i<=x; i++)
                        if(m[s[i]-'a'])
                            f = false;
            }
        }
        else
        {
            if(l!=n)  f = false;
            else
            {
                for(int i=0; f&&i<n; i++)
                {
                    if(t[i]=='?'&&m[s[i]-'a']==1)continue;
                    if(s[i]!=t[i]) f = false;
                }
            }
        }
        if(f)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0 ;
}


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    int z = 0;
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            z++;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        int x = 0;
        for(int i = 0 ; i < ll ; i++){
            int j = i;
            if(a[t[j]-'a']) continue;
            while(t[j]&&a[t[j]-'a']==0)
                j++;
            t[i] = '*';
            for(int k = j ; k < ll ; k++)
                t[i+k-j+1] = t[k];
            ll = ll-(j-i)+1;

            x++;
        }
        if(x>1)
            f = false;
        if(z){
            if(l==ll){
                for(int i = 0 ; f&&i < ll ; i++){
                    if(s[i]=='?'&&a[t[i]-'a'])continue;
                    if(s[i]!=t[i]) f = false;
                }
            }
            else if(l == ll+1){
                int j = 0;
                bool y = true;
                for(int i = 0 ; i < l ; i++){
                    if(s[i]=='*')continue;
                    if(s[i]=='?'&&a[t[i]-'a']);
                    else if(s[i]!=s[j])
                        y = false;
                    j++;
                }
                if(!y)
                    f = false;
            }
            else f = false;
        }
        else {
            if(l != ll)
                f = false;
            else{
                for(int i = 0 ; f&&i < ll ; i++){
                    if(t[i]=='*')f = false;
                    if(s[i]=='?'&&a[t[i]-'a'])continue;
                    if(s[i]!=t[i]) f = false;
                }
            }
        }

        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            for(int j = i ; j < l-1 ; j++)
                s[j] = s[j+1];
            l--;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        int x = 0;
        for(int i = 0 ; i < ll ; i++){
            int j = i;
            if(a[t[j]-'a']) continue;
            while(t[j]&&a[t[j]-'a']==0)
                j++;
            for(int k = j ; k < ll ; k++)
                t[i+k-j] = t[k];
            ll = ll-(j-i);
            x++;
        }
        if(x>1)
            f = false;
        if(l != ll)
            f = false;
        for(int i = 0 ; f&&i < ll ; i++){
            if(s[i]=='?'&&a[t[i]-'a'])continue;
            if(s[i]!=t[i]) f = false;
        }
        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    int z = 0;
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            z++;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        int x = 0;
        for(int i = 0 ; i < ll ; i++){
            int j = i;
            if(a[t[j]-'a']) continue;
            while(t[j]&&a[t[j]-'a']==0)
                j++;
            t[i] = '*';
            for(int k = j ; k < ll ; k++)
                t[i+k-j+1] = t[k];
            ll = ll-(j-i)+1;

            x++;
        }
        if(x>1)
            f = false;
        if(z){
            if(l==ll);
            else if(l = ll+1){
                int j = 0;
                bool y = true;
                for(int i = 0 ; i < l ; i++){
                    if(s[i]=='*')continue;
                    if(s[i]!=s[j])
                        y = false;
                    j++;
                }
                if(!y)
                    f = false;
            }
            else f = false;
        }
        else {
            if(l != ll)
                f = false;
        }
        for(int i = 0 ; f&&i < ll ; i++){
            if(s[i]=='?'&&a[t[i]-'a'])continue;
            if(s[i]!=t[i]) f = false;
        }
        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    int z = 0;
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            z++;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        if(ll >= l-1){
            int i = 0,j = l-1,k = ll-1;
            for(;i < l ; i++){
                if(s[i] == t[i]) continue;
                if(s[i]=='?'){
                    if(a[t[i]-'a']==0)
                        f = false;
                    continue;
                }
                if(s[i]=='*')
                    break;
                f = false;
            }
            for(;j>=0 , k>=0 ; j--,k--){
                if(s[j]==t[k])continue;
                if(s[j]=='?'){
                    if(a[t[k]-'a']==0)
                        f = false;
                    continue;
                }
                if(s[j]=='*')
                    break;
                f = false;
            }
            for(int j = i ; j <= k ; j++)
                if(a[t[j]-'a'])
                f = false;
        }
        else f = false;
        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


#include<bits/stdc++.h>
#define PB(u)  push_back(u)
#define AA   first
#define BB   second
#define inf 0x3f3f3f3f
using namespace std ;
#define MAX 100005
#define sz size()
typedef long long ll ;
typedef pair<int,int> PII ;
const double eps=1e-8;
const double pi=acos(-1.0);
const int mod=1e9+7;

char s[MAX],t[MAX];
map<char,int>  m;

int main()
{
    scanf(" %s %s",s,t);
    int len=strlen(s);
    for(int i=0; i<len; i++)
        m[s[i]]=1;
    int n=strlen(t);
    int id = -1;
    for(int i=0; i<n; i++)
    {
        if(t[i]=='*')
        {
            id=i;
        }
    }
    int T;
    cin>>T;
    while(T--)
    {
        scanf("%s",s);
        int l=strlen(s);
        bool f = true;
        if(id>0)
        {
            for(int i=0; i<id; i++)
            {
                if(s[i]==t[i]||(t[i]=='?'&&m.find(s[i])!=m.end())) ;
                else f = false;
            }
            if(l<n-1) f = false;
            else
            {
                int x=l-1;
                for(int i=n-1; i>id ; x--,i--)
                {
                    if(s[x]==t[i]||(t[i]=='?'&&m.find(s[x])!=m.end())) ;
                    else f = false;
                }
                if(x<id-1)
                    f = false;
                else
                    for(int i=id; i<=x; i++)
                        if(m.find(s[i])!=m.end())
                            f = false;
            }
        }
        else
        {
            if(l!=n)  f = false;
            else
            {
                for(int i=0; f&&i<n; i++)
                {
                    if(t[i]=='?'&&m[s[i]]==1)continue;
                    if(s[i]!=t[i]) f = false;
                }
            }
        }
        if(f)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0 ;
}


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    int z = 0;
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            z++;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        if(ll >= l-1){
            int i = 0,j = l-1,k = ll-1;
            for(;i < l ; i++){
                if(s[i] == t[i]) continue;
                if(s[i]=='?'){
                    if(a[t[i]-'a']==0)
                        f = false;
                    continue;
                }
                if(s[i]=='*')
                    break;
                f = false;
            }
            for(;j>=0 && k>=0 ; j--,k--){
                if(s[j]==t[k])continue;
                if(s[j]=='?'){
                    if(a[t[k]-'a']==0)
                        f = false;
                    continue;
                }
                if(s[j]=='*')
                    break;
                f = false;
            }
            for(int j = i ; j <= k ; j++)
                if(a[t[j]-'a'])
                f = false;
        }
        else f = false;
        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    int z = 0;
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            z++;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        int x = 0;
        for(int i = 0 ; i < ll ; i++){
            int j = i;
            if(a[t[j]-'a']) continue;
            while(t[j]&&a[t[j]-'a']==0)
                j++;
            t[i] = '*';
            for(int k = j ; k < ll ; k++)
                t[i+k-j+1] = t[k];
            ll = ll-(j-i)+1;

            x++;
        }
        if(x>1)
            f = false;
        if(z){
            if(l==ll);
            else if(l == ll+1){
                int j = 0;
                bool y = true;
                for(int i = 0 ; i < l ; i++){
                    if(s[i]=='*')continue;
                    if(s[i]!=s[j])
                        y = false;
                    j++;
                }
                if(!y)
                    f = false;
            }
            else f = false;
        }
        else {
            if(l != ll)
                f = false;
        }
        for(int i = 0 ; f&&i < ll ; i++){
            if(s[i]=='?'&&a[t[i]-'a'])continue;
            if(s[i]!=t[i]) f = false;
        }
        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


/*    brioso     */
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define SQ(x) ((x)*(x))
#define MT(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll ;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps =1e-8;
const int mod = 1000000007;
#define MAXN 100500
#define inf 0x3f3f3f3f

struct node{
    int x,y;
    node(){}
    node(int xx,int yy):x(xx),y(yy){}
    bool operator < (const node a) const{
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
};
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char s[MAXN];
char t[MAXN];
bool vis[MAXN];
int n,m;
int ans;

int main()
{
    //freopen("1.txt","r",stdin);
    int tt,ca = 1;
    int p,q;
    scanf("%s%s",t,s);
    int l = strlen(t);
    for(int i = 0 ; i < l ; i++)
        a[t[i]-'a'] = 1;
    scanf("%d",&n);
    l = strlen(s);
    int z = 0;
    for(int i = 0 ; i < l ; i++){
        if(s[i]=='*'){
            z++;
        }
    }
    while(n--){
        scanf("%s",t);
        int ll = strlen(t);
        bool f = true;
        int x = 0;
        for(int i = 0 ; i < ll ; i++){
            int j = i;
            if(a[t[j]-'a']) continue;
            while(t[j]&&a[t[j]-'a']==0)
                j++;
            t[i] = '*';
            for(int k = j ; k < ll ; k++)
                t[i+k-j+1] = t[k];
            ll = ll-(j-i)+1;

            x++;
        }
        if(x>1)
            f = false;
        if(z){
            if(l==ll){
                for(int i = 0 ; f&&i < ll ; i++){
                    if(s[i]=='?'&&a[t[i]-'a'])continue;
                    if(s[i]!=t[i]) f = false;
                }
            }
            else if(l == ll+1){
                int j = 0;
                bool y = true;
                for(int i = 0 ; i < l ; i++){
                    if(s[i]=='*')continue;
                    if(s[i]=='?'&&a[t[j]-'a']);
                    else if(s[i]!=t[j])
                        y = false;
                    j++;
                }
                if(!y)
                    f = false;
            }
            else f = false;
        }
        else {
            if(l != ll)
                f = false;
            else{
                for(int i = 0 ; f&&i < ll ; i++){
                    if(t[i]=='*')f = false;
                    if(s[i]=='?'&&a[t[i]-'a'])continue;
                    if(s[i]!=t[i]) f = false;
                }
            }
        }

        if(f)
            printf("YES\n");
        else printf("NO\n");
    }

    //printf("%d\n",ans);
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
long long的最大值：9223372036854775807   (__int64)
unsigned long long的最大值：18446744073709551615   (unsigned __int64)

*/


#include<bits/stdc++.h>
#define PB(u)  push_back(u)
#define AA   first
#define BB   second
#define inf 0x3f3f3f3f
using namespace std ;
#define MAX 100005
#define sz size()
typedef long long ll ;
typedef pair<int,int> PII ;
const double eps=1e-8;
const double pi=acos(-1.0);
const int mod=1e9+7;

char s[MAX],t[MAX];
int m[300];

int main()
{
    scanf(" %s %s",s,t);
    int len=strlen(s);
    for(int i=0; i<len; i++)
        m[s[i]-'a']=1;
    int n=strlen(t);
    int id = -1;
    for(int i=0; i<n; i++)
    {
        if(t[i]=='*')
        {
            id=i;
        }
    }
    int T;
    cin>>T;
    while(T--)
    {
        scanf("%s",s);
        int l=strlen(s);
        bool f = true;
        if(id>0)
        {
            for(int i=0; i<id; i++)
            {
                if(s[i]==t[i]||(t[i]=='?'&&m[s[i]-'a'])) ;
                else f = false;
            }
            if(l<n-1) f = false;
            else
            {
                int x=l-1;
                for(int i=n-1; i>id ; x--,i--)
                {
                    if(s[x]==t[i]||(t[i]=='?'&&m[s[i]-'a'])) ;
                    else f = false;
                }
                if(x<id-1)
                    f = false;
                else
                    for(int i=id; i<=x; i++)
                        if(m[s[i]-'a'])
                            f = false;
            }
        }
        else
        {
            if(l!=n)  f = false;
            else
            {
                for(int i=0; f&&i<n; i++)
                {
                    if(t[i]=='?'&&m[s[i]-'a']==1)continue;
                    if(s[i]!=t[i]) f = false;
                }
            }
        }
        if(f)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0 ;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 100010;
string x1,x2;
int a[150];
int b[maxn];
int main()
{
    ios::sync_with_stdio(0);
    memset(a,0,sizeof(a));
    cin>>x1>>x2;
    int len = x1.size();
    int len1 = x2.size();
    for(int i = 0; i < len; ++i){
        a[x1[i]] = 1;
    }
    int p = 0,pos1 = -1;
    for(int i=0;i<len1;++i){
        if(x2[i]=='?')
            b[++p] = i;
        if(x2[i]=='*')
            pos1 = i;
    }

    int n;
    cin >> n;
    for(int i=1;i<=n;++i){
        int k = p;
        string x3;
        cin >> x3;
        int len2 = x3.size();
         string x5 = x2;
         if(len1>len2+1){
            cout << "NO" << endl;
            continue;
         }
         int t,len3;
         if(len1==len2+1){
            if(pos1==-1){
               cout << "NO" << endl;
            continue;
            }
           else if(pos1==len1-1)
            x5 = x2.substr(0,pos1);
            else
            x5 = x2.substr(0,pos1)+x2.substr(pos1+1,len1-pos1-1);
           len3 = x5.size();
           if(len3>len2){
             cout << "NO" << endl;
            continue;
           }
          // cout << x5 << endl;
            for(t=1;t<=k;++t){
                if((x5[b[t]]=='?'&&a[x3[b[t]]]!=1)){
                    break;

            }
        x5[b[t]] = x3[b[t]];
         }
         //cout << x5 <<t<< endl;
         if(t>k&&x5==x3){
            cout << "YES" << endl;
            continue;
        }
        else{
            cout << "NO" << endl;
            continue;
        }
         }
        if(len1==len2){
        x5 = x2;
        if(pos1!=-1)
        b[++k] = pos1;
        for(t=1;t<=k;++t){
            if((x2[b[t]]=='?'&&a[x3[b[t]]]!=1)||(x2[b[t]]=='*'&&a[x3[b[t]]]==1)){
                break;
            }
            x5[b[t]] = x3[b[t]];
        }
        //cout << x5 << k<<" "<<b[1]<<" "<<b[2]<<endl;
        if(t>k&&x5==x3){
            cout << "YES" << endl;
            continue;
        }
        else{
            cout << "NO" << endl;
            continue;
        }
         }
       if(len1<len2){
            //cout << "hh" << endl;
            if(pos1==-1){
            cout << "NO" << endl;
            continue;
            }
            else{
                x5 = x2.substr(0,pos1);
                if(x5!=x3.substr(0,pos1)){
                     cout << "NO" << endl;
                    continue;
                }
                 else if(pos1 == len1-1){
                    for(t=pos1+1;t<len2;++t){
                        if(a[x3[t]]==1)
                            break;
                    }
                    if(t==len2){
                        cout << "YES" << endl;
                        continue;
                    }
                    else{
                        cout << "NO" << endl;
                        continue;
                    }
                 }
                 else{
                    string x6 = x3.substr(pos1+1,len2-pos1-1);
                    string x7 = x5.substr(pos1+1,len1-pos1-1);
                    if(x6.rfind(x7)==std::string::npos){
                         cout << "NO" << endl;
                        continue;
                    }
                    else{
                        int pos2 = x6.rfind(x7);
                        for(t=pos1+1;t<=pos2;++t){
                            if(a[x3[t]]==1)
                                break;
                        }
                        if(t==pos2+1){
                        cout << "YES" << endl;
                        continue;
                    }
                    else
                        cout << "NO" << endl;
                        continue;
                    }
                 }
            }
       }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 100010;
string x1,x2;
int a[150];
int b[maxn];
int main()
{
    ios::sync_with_stdio(0);
    memset(a,0,sizeof(a));
    cin>>x1>>x2;
    int len = x1.size();
    int len1 = x2.size();
    for(int i = 0; i < len; ++i){
        a[x1[i]] = 1;
    }
    int p = 0,pos1 = -1;
    for(int i=0;i<len1;++i){
        if(x2[i]=='?')
            b[++p] = i;
        if(x2[i]=='*')
            pos1 = i;
    }

    int n;
    cin >> n;
    for(int i=1;i<=n;++i){
        int k = p;
        string x3;
        cin >> x3;
        int len2 = x3.size();
         string x5 = x2;
         if(len1>len2+1){
            cout << "NO" << endl;
            continue;
         }
         int t,len3;
         if(len1==len2+1){
            if(pos1==-1){
               cout << "NO" << endl;
            continue;
            }
           else if(pos1==len1-1)
            x5 = x2.substr(0,pos1);
            else
            x5 = x2.substr(0,pos1)+x2.substr(pos1+1,len1-pos1-1);
           len3 = x5.size();
           if(len3>len2){
             cout << "NO" << endl;
            continue;
           }
          // cout << x5 << endl;
            for(t=1;t<=k;++t){
                if((x5[b[t]]=='?'&&a[x3[b[t]]]!=1)){
                    break;

            }
        x5[b[t]] = x3[b[t]];
         }
         //cout << x5 <<t<< endl;
         if(t>k&&x5==x3){
            cout << "YES" << endl;
            continue;
        }
        else{
            cout << "NO" << endl;
            continue;
        }
         }
        if(len1==len2){
        x5 = x2;
        if(pos1!=-1)
        b[++k] = pos1;
        for(t=1;t<=k;++t){
            if((x2[b[t]]=='?'&&a[x3[b[t]]]!=1)||(x2[b[t]]=='*'&&a[x3[b[t]]]==1)){
                break;
            }
            x5[b[t]] = x3[b[t]];
        }
        //cout << x5 << k<<" "<<b[1]<<" "<<b[2]<<endl;
        if(t>k&&x5==x3){
            cout << "YES" << endl;
            continue;
        }
        else{
            cout << "NO" << endl;
            continue;
        }
         }
       if(len1<len2){
            //cout << "hh" << endl;
            if(pos1==-1){
            cout << "NO" << endl;
            continue;
            }
            else{
                x5 = x2.substr(0,pos1);
                if(x5!=x3.substr(0,pos1)){
                     cout << "NO" << endl;
                    continue;
                }
                 else if(pos1 == len1-1){
                       // cout << "HH" << endl;
                    for(t=pos1;t<len2;++t){
                        if(a[x3[t]]==1)
                            break;
                    }
                    if(t==len2){
                        cout << "YES" << endl;
                        continue;
                    }
                    else{
                        cout << "NO" << endl;
                        continue;
                    }
                 }
                 else{
                    //string x6 = x3.substr(pos1+1,len2-pos1-1);
                    string x7 = x2.substr(pos1+1,len1-pos1-1);
                    int len4 = x7.size();
                    if(x3.rfind(x7)==std::string::npos||x3.rfind(x7)+len4!=len2){
                         cout << "NO" << endl;
                        continue;
                    }
                    else{
                        int pos2 = x3.rfind(x7);
                        for(t=pos1;t<=pos2;++t){
                            if(a[x3[t]]==1)
                                break;
                        }
                        if(t==pos2+1){
                        cout << "YES" << endl;
                        continue;
                    }
                    else
                        cout << "NO" << endl;
                        continue;
                    }
                 }
            }
       }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 100010;
string x1,x2;
int a[150];
int b[maxn];
int main()
{
    ios::sync_with_stdio(0);
    memset(a,0,sizeof(a));
    cin>>x1>>x2;
    int len = x1.size();
    int len1 = x2.size();
    for(int i = 0; i < len; ++i){
        a[x1[i]] = 1;
    }
    int p = 0,pos1 = -1;
    for(int i=0;i<len1;++i){
        if(x2[i]=='?')
            b[++p] = i;
        if(x2[i]=='*')
            pos1 = i;
    }

    int n;
    cin >> n;
    for(int i=1;i<=n;++i){
        int k = p;
        string x3;
        cin >> x3;
        int len2 = x3.size();
         string x5 = x2;
         if(len1>len2+1){
            cout << "NO" << endl;
            continue;
         }
         int t,len3;
         if(len1==len2+1){
            if(pos1==len1-1)
            x5 = x2.substr(0,pos1);
            else
            x5 = x2.substr(0,pos1)+x2.substr(pos1+1,len1-pos1-1);
           len3 = x5.size();
           if(len3>len2){
             cout << "NO" << endl;
            continue;
           }
          // cout << x5 << endl;
            for(t=1;t<=k;++t){
                if((x5[b[t]]=='?'&&a[x3[b[t]]]!=1)){
                    break;

            }
        x5[b[t]] = x3[b[t]];
         }
         //cout << x5 <<t<< endl;
         if(t>k&&x5==x3){
            cout << "YES" << endl;
            continue;
        }
        else{
            cout << "NO" << endl;
            continue;
        }
         }
        if(len1==len2){
        x5 = x2;
        if(pos1!=-1)
        b[++k] = pos1;
        for(t=1;t<=k;++t){
            if((x2[b[t]]=='?'&&a[x3[b[t]]]!=1)||(x2[b[t]]=='*'&&a[x3[b[t]]]==1)){
                break;
            }
            x5[b[t]] = x3[b[t]];
        }
        //cout << x5 << k<<" "<<b[1]<<" "<<b[2]<<endl;
        if(t>k&&x5==x3){
            cout << "YES" << endl;
            continue;
        }
        else{
            cout << "NO" << endl;
            continue;
        }
         }
       if(len1<len2){
            if(pos1==-1){
            cout << "NO" << endl;
            continue;
            }
            else{
                x5 = x2.substr(0,pos1);
                if(x5!=x3.substr(0,pos1)){
                     cout << "NO" << endl;
                    continue;
                }
                 else if(pos1 == len1-1){
                    for(t=pos1+1;t<len2;++t){
                        if(a[x3[t]]!=1)
                            break;
                    }
                    if(t==len2){
                        cout << "YES" << endl;
                        continue;
                    }
                    else{
                        cout << "NO" << endl;
                        continue;
                    }
                 }
                 else{
                    string x6 = x3.substr(pos1+1,len2-pos1-1);
                    string x7 = x5.substr(pos1+1,len1-pos1-1);
                    if(x6.rfind(x7)==std::string::npos){
                         cout << "NO" << endl;
                        continue;
                    }
                    else{
                        int pos2 = x6.rfind(x7);
                        for(t=pos1+1;t<=pos2;++t){
                            if(a[x3[t]]!=1)
                                break;
                        }
                        if(t==pos2+1){
                        cout << "YES" << endl;
                        continue;
                    }
                    else
                        cout << "NO" << endl;
                        continue;
                    }
                 }
            }
       }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 100010;
string x1,x2;
int a[150];
int b[maxn];
int main()
{
    ios::sync_with_stdio(0);
    memset(a,0,sizeof(a));
    cin>>x1>>x2;
    int len = x1.size();
    int len1 = x2.size();
    for(int i = 0; i < len; ++i){
        a[x1[i]] = 1;
    }
    int k = 0;
    for(int i=0;i<len1;++i){
        if(x2[i]=='?'||x2[i]=='*')
            b[++k] = i;
    }
    int n;
    cin >> n;
    for(int i=1;i<=n;++i){
        string x3;
        cin >> x3;
        int len2 = x3.size();
         string x5 = x2;
        if(len1>len2){
            string x4 = x2.substr(len2,len1-len2);
            int j;
            for( j=0;j<len1-len2;++j){
                if(x4[j]!='*')
                    break;
            }
            if(j!=len1-len2){
                cout << "NO" << endl;
                continue;
            }
            x5 = x5.substr(0,len2);
        }

        //cout << x5 << endl;
        int t;
        for(t=1;t<=k;++t){
            if((x2[b[t]]=='?'&&a[x3[b[t]]]!=1)||(x2[b[t]]=='*'&&a[x3[b[t]]]==1)){
                break;
            }
            x5[b[t]] = x3[b[t]];
        }
        //cout << x5 << k<<" "<<b[1]<<" "<<b[2]<<endl;
        if(t>k&&x5==x3.substr(0,len1)){
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define max_n 100010
char a[max_n],b[max_n],c[max_n];
int d[1010];

int main()
{
	int n,res=0;
	memset(d,0,sizeof(d));
	scanf("%s",a);
	getchar();
	for(int i=0;i<strlen(a);i++)
	{
		d[a[i]]=1;
	}
	scanf("%s",b);
	getchar();
	for(int i=0;i<strlen(b);i++)
	{
		if(b[i]=='*')
		{
			res++;
			break;
		}
	}
	int len1=strlen(b);
	scanf("%d",&n);
	while(n--)
	{
		bool flag=true;
		memset(c,0,sizeof(c));
		scanf("%s",c);
		int cnt=0;
		int len2=strlen(c);
		int len=max(len1,len2);
		int ans=abs(len1-len2);
		if(res==0 && ans!=0)
		{
			printf("NO\n");
			continue;
		}
		if(res==1 && len1-len2>=2)
		{
			printf("NO\n");
			continue;
		}
		for(int i=0;i<len1;i++)
		{
			if(b[i]=='?')
			{
				if(d[c[i+cnt]]!=1)
					flag=false;
			}
			else if(b[i]=='*')
			{
				 for(int j=i;j<=len2-len1+i;j++)
				 {
				 	if(d[c[j]])
					 {
					 	flag=false;
					 	break;
					 }
				 }
				 cnt=len2-len1;
			}
			else
			{
				if(b[i]!=c[i+cnt])
					flag=false;
			}
			if(!flag) break;
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}