#include<bits/stdc++.h>
using namespace std;
char s[30];
int ty[30];
char ned[202];
int ls;
int len;
int n,m;
bool mark[500];
int rep[500];
vector<int>G[500];
vector<int>tp;
int op;
int getid(int x,char c)
{
	return c=='V'?(x<<1):(x<<1|1);
}
int find(int st,int Ty)
{
	for(int i=st;i<ls;i++)
		if(ty[i]==Ty)
			return i;
	return ls;
}
bool dfs(int u)
{
	if(mark[u])return 1;
	if(mark[u^1])return 0;
	int l=u>>1;
	int Ty=u>(u^1)?1:0;
	mark[u]=1;
	tp.push_back(u);
	if(l<=len)
	{
		if(ty[ned[l]-'a']!=Ty)return false;
		rep[l]=ned[l]-'a';
	}
	else
	{
		int c=find(l==len+1?(ned[l]-'a'+1):0,Ty);
		if(c==ls)return false;
		rep[l]=c;
	}
	for(int i=0;i<G[u].size();i++)
		if(!dfs(G[u][i]))
			return false;
	return true;
}
bool check()
{
	memset(mark,0,sizeof(mark));
	for(int i=1;i<=n;i++)
	{
		int c=ned[i]-'a';
		if(i<=len)
		{
			if(!dfs(i<<1|ty[c]))return false;
		}
		else
		{
			if(mark[i<<1]||mark[i<<1|1])continue;
			int a,b;
			if(i==len+1){a=find(c+1,0);b=find(c+1,1);}
			else {a=find(0,0);b=find(0,1);}
			int fid,fa;
			if(a<b)fid=i<<1,fa=a;else fid=i<<1|1,fa=b;
			//if(fa==ls)return false;
			tp.clear();
			if(!dfs(fid))
			{
				for(int j=0;j<tp.size();j++)mark[tp[j]]=0;
				if(a+b-fa==ls||!dfs(fid^1))return false;
			}
		}
	}
	for(int i=1;i<=n;i++)putchar(rep[i]+'a');
	return 1;
}
int main()
{
	scanf("%s",s);
	ls=strlen(s);
	for(int i=0;i<ls;i++)ty[i]=s[i]=='V'?0:1;
	scanf("%d%d",&n,&m);
	//V:0,C:1
	for(int i=0;i<m;i++)
	{
		int x;
		char c;
		scanf("%d %c",&x,&c);
		int id1=getid(x,c);
		scanf("%d %c",&x,&c);
		int id2=getid(x,c);
		G[id1].push_back(id2);
		G[id2^1].push_back(id1^1);
	}
	scanf("%s",ned+1);
	for(len=n;len>=0;len--)
	{
		if(check())return 0;
	}
	puts("-1");
}


#include<bits/stdc++.h>
using namespace std;
char s[30];
int ty[30];
char ned[202];
int ls;
int len;
int n,m;
bool mark[500];
int rep[500];
vector<int>G[500];
vector<int>tp;
int op;
int getid(int x,char c)
{
	return c=='V'?(x<<1):(x<<1|1);
}
int find(int st,int Ty)
{
	for(int i=st;i<ls;i++)
		if(ty[i]==Ty)
			return i;
	return ls;
}
bool dfs(int u)
{
	if(mark[u])return 1;
	if(mark[u^1])return 0;
	int l=u>>1;
	int Ty=u>(u^1)?1:0;
	mark[u]=1;
	tp.push_back(u);
	if(l<=len)
	{
		if(ty[ned[l]-'a']!=Ty)return false;
		rep[l]=ned[l]-'a';
	}
	else
	{
		int c=find(l==len+1?(ned[l]-'a'+1):0,Ty);
		if(c==ls)return false;
		rep[l]=c;
	}
	for(int i=0;i<G[u].size();i++)
		if(!dfs(G[u][i]))
			return false;
	return true;
}
bool check()
{
	memset(mark,0,sizeof(mark));
	for(int i=1;i<=n;i++)
	{
		if(mark[i<<1]||mark[i<<1|1])continue;
		int c=ned[i]-'a';
		if(i<=len)
		{
			if(!dfs(i<<1|ty[c]))return false;
		}
		else
		{

			int a,b;
			if(i==len+1){a=find(c+1,0);b=find(c+1,1);}
			else {a=find(0,0);b=find(0,1);}
			int fid,fa;
			if(a<b)fid=i<<1,fa=a;else fid=i<<1|1,fa=b;
			//if(fa==ls)return false;
			tp.clear();
			if(!dfs(fid))
			{
				for(int j=0;j<tp.size();j++)mark[tp[j]]=0;
				if(a+b-fa==ls||!dfs(fid^1))return false;
			}
		}
	}
	for(int i=1;i<=n;i++)putchar(rep[i]+'a');
	return 1;
}
int main()
{
	scanf("%s",s);
	ls=strlen(s);
	for(int i=0;i<ls;i++)ty[i]=s[i]=='V'?0:1;
	scanf("%d%d",&n,&m);
	//V:0,C:1
	for(int i=0;i<m;i++)
	{
		int x;
		char c;
		scanf("%d %c",&x,&c);
		int id1=getid(x,c);
		scanf("%d %c",&x,&c);
		int id2=getid(x,c);
		G[id1].push_back(id2);
		G[id2^1].push_back(id1^1);
	}
	scanf("%s",ned+1);
	for(len=n;len>=0;len--)
	{
		if(check())return 0;
	}
	puts("-1");
}


#include<bits/stdc++.h>
using namespace std;
#define REP(n) for(int i=0;i<n;i++)
#define mp make_pair
typedef pair<int,int> pii;
const int maxn = 200000+20;
int n,m;
vector<pii> G[maxn],X[maxn];
bool used[maxn];
int ans[maxn];
int f[maxn];
int find(int x)
{
	return f[x] = x==f[x]?x:find(f[x]);
}
bool uni_set(int x,int y)
{
	int u = find(x),v = find(y);
	if(u == v) return false;
	f[u] = v;
	return true;
}
void gao(int x,int y)
{
	if(X[y][0].first == x)
		ans[y] = X[y][0].second;
	if(X[y][1].first == x)
		ans[y] = X[y][1].second;
}
void dfs(int u)
{
	used[u] = 1;
	for(int i=0;i<G[u].size();i++)
	{
		pii p = G[u][i];
		int v = p.first;
		if(used[v]) continue;
		gao(v,p.second);
		dfs(v);
	}
}
int main()
{
	scanf("%d%d",&n,&m);

	int t;
	for(int i=0;i<n;i++)
	{
		f[i] = i;
		scanf("%d",&t);int tt;
		REP(t)
		{
			scanf("%d",&tt);
			if(tt>0) X[tt].push_back(mp(i,1));
			else X[-tt].push_back(mp(i,0));
		}
	}

	for(int i=1;i<=m;i++)
		if(X[i].size()==1)
	    {
			ans[i] = X[i][0].second;
	    	dfs(X[i][0].first);
	    }
	    else if(X[i].size()==2)
		{
			if(X[i][0].second == X[i][1].second)
			{
				ans[i] = X[i][0].second;
				dfs(X[i][0].first);
				dfs(X[i][1].first);
				uni_set(X[i][0].first,X[i][1].first);
			}
			else
			{
				if(used[X[i][0].first])
				{
					ans[i] = X[i][1].second;
					dfs(X[i][1].first);
					uni_set(X[i][0].first,X[i][1].first);
				}
				else if(used[X[i][1].first])
				{
					ans[i] = X[i][0].second;
					dfs(X[i][0].first);
					uni_set(X[i][0].first,X[i][1].first);
				}
				else if(!uni_set(X[i][0].first,X[i][1].first))
				{
					ans[i] = X[i][0].second;
					dfs(X[i][0].first);
				}
				else
				{
					G[X[i][0].first].push_back(mp(X[i][1].first,i));
					G[X[i][1].first].push_back(mp(X[i][0].first,i));
					uni_set(X[i][0].first,X[i][1].first);
				}
			}
		}
	bool flag = 1;
	for(int i=0;i<n;i++)
		flag &= used[i];
	if(!flag)
	{
		puts("NO");
		return 0;
	}
	puts("YES");
	for(int i=1;i<=m;i++)
		printf("%d",ans[i]);
	puts("");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char s[30];
int ty[30];
char ned[202];
int ls;
int len;
int n,m;
bool mark[500];
int rep[500];
vector<int>G[500];
vector<int>tp;
int op;
int getid(int x,char c)
{
	return c=='V'?(x<<1):(x<<1|1);
}
int find(int st,int Ty)
{
	for(int i=st;i<ls;i++)
		if(ty[i]==Ty)
			return i;
	return ls;
}
bool dfs(int u)
{
	if(mark[u])return 1;
	if(mark[u^1])return 0;
	int l=u>>1;
	int Ty=u>(u^1)?1:0;
	mark[u]=1;
	tp.push_back(u);
	if(l<=len)
	{
		if(ty[ned[l]-'a']!=Ty)return false;
		rep[l]=ned[l]-'a';
	}
	else
	{
		int c=find(l==len+1?(ned[l]-'a'+1):0,Ty);
		if(c==ls)return false;
		rep[l]=c;
	}
	for(int i=0;i<G[u].size();i++)
		if(!dfs(G[u][i]))
			return false;
	return true;
}
bool check()
{
	memset(mark,0,sizeof(mark));
	for(int i=1;i<=n;i++)
	{
		int c=ned[i]-'a';
		if(i<=len)
		{
			if(!dfs(i<<1|ty[c]))return false;
		}
		else
		{
			if(mark[i<<1]||mark[i<<1|1])continue;
			int a,b;
			if(i==len+1){a=find(c+1,0);b=find(c+1,1);}
			else {a=find(0,0);b=find(0,1);}
			int fid,fa;
			if(a<b)fid=i<<1,fa=a;else fid=i<<1|1,fa=b;
			if(fa==ls)return false;
			tp.clear();
			if(!dfs(fid))
			{
				for(int j=0;j<tp.size();j++)mark[tp[j]]=0;
				if(a+b-fa==ls||!dfs(fid^1))return false;
			}
		}
	}
	for(int i=1;i<=n;i++)putchar(rep[i]+'a');
	return 1;
}
int main()
{
	scanf("%s",s);
	ls=strlen(s);
	for(int i=0;i<ls;i++)ty[i]=s[i]=='V'?0:1;
	scanf("%d%d",&n,&m);
	//V:0,C:1
	for(int i=0;i<m;i++)
	{
		int x;
		char c;
		scanf("%d %c",&x,&c);
		int id1=getid(x,c);
		scanf("%d %c",&x,&c);
		int id2=getid(x,c);
		G[id1].push_back(id2);
		//G[id2^1].push_back(id1^1);
	}
	scanf("%s",ned+1);
	for(len=n;len>=0;len--)
	{
		if(check())return 0;
	}
	puts("-1");
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 400 + 10;
char ch[30];int xx[30],xxlen;
int getid(int x,char c)
{
	return c=='V'?(x<<1):(x<<1|1);
}
int find(int st,int Ty)
{
	for(int i=st;i<xxlen;i++)
		if(xx[i]==Ty)
			return i;
	return xxlen;
}
int n,m;
vector<int> G[maxn],tp;
char s[maxn/2];int ss[maxn/2];int limit;
bool mark[maxn];
/*bool dfs(int x)
{
	if(mark[x]) return true;
	if(mark[x^1]) return false;
	int l = x/2;
	int L = x>(x^1);
	mark[x] = 1;
	tp.push_back(x);
	if(l<=limit)
	{
		if(xx[s[l]-'a']!=L) return false;
		ss[l] = s[l]-'a';
	}
	else
	{
		int c=find(l==len+1?(s[l]-'a'+1):0,L);
		if(c==xxlen)return false;
		ss[l]=c;
	}
	for(int i=0;i<G[x].size();i++)
		if(!dfs(G[x][i]))
			return false;
	return true;
}*/
bool dfs(int u)
{
	if(mark[u])return 1;
	if(mark[u^1])return 0;
	int l=u>>1;
	int Ty=u>(u^1)?1:0;
	mark[u]=1;
	tp.push_back(u);
	if(l<=limit)
	{
		if(xx[s[l]-'a']!=Ty)return false;
		ss[l]=s[l]-'a';
	}
	else
	{
		int c=find(l==limit+1?(s[l]-'a'+1):0,Ty);
		if(c==xxlen)return false;
		ss[l]=c;
	}
	for(int i=0;i<G[u].size();i++)
		if(!dfs(G[u][i]))
			return false;
	return true;
}

/*bool solve()
{
	memset(mark,0,sizeof(mark));
	for(int i=1;i<=n;i++)
	{
		if(mark[i*2]||mark[i*2+1]) continue;
		if(i<=limit)
		{
			if(!dfs(i*2+xx[s[i]-'a'])) return false;
		}
		else
		{
			int p0 = find(i==limit+1?s[i]-'a'+1:0,0),p1 = find(i==limit+1?s[i]-'a'+1:0,1);
			int pp,pa;
			if(p0<p1) pp = 2*i,pa = p0;
			else pp = 2*i+1,pa = p1;
			tp.clear();
			if(!dfs(pp))
			{
				for(int j=0;j<tp.size();j++)
				    mark[tp[j]] = 0;
				if(p0+p1-pa == xxlen||!dfs(pp^1)) return false;
			}
		}
	}
	for(int i=1;i<=n;i++)
		putchar('a'+ss[i]);
	return true;
}*/

bool check()
{
	memset(mark,0,sizeof(mark));
	//cout<<limit<<endl;
	for(int i=1;i<=n;i++)
	{
		if(mark[i<<1]||mark[i<<1|1])continue;
		int c=s[i]-'a';
		if(i<=limit)
		{
			if(!dfs(i<<1|xx[c]))return false;
		}
		else
		{

			int a,b;
			if(i==limit+1){a=find(c+1,0);b=find(c+1,1);}
			else {a=find(0,0);b=find(0,1);}
			int fid,fa;
			if(a<b)fid=i<<1,fa=a;else fid=i<<1|1,fa=b;
			//if(fa==ls)return false;
			tp.clear();
			if(!dfs(fid))
			{
				for(int j=0;j<tp.size();j++)mark[tp[j]]=0;
				if(a+b-fa==xxlen||!dfs(fid^1))return false;
			}
		}
	}
	for(int i=1;i<=n;i++)putchar(ss[i]+'a');
	return 1;
}
int main()
{
	scanf("%s",ch);
	xxlen=strlen(ch);
	for(int i=0;i<xxlen;i++)xx[i]=ch[i]=='V'?0:1;
	scanf("%d%d",&n,&m);
	//V:0,C:1
	for(int i=0;i<m;i++)
	{
		int x;
		char c;
		scanf("%d %c",&x,&c);
		int id1=getid(x,c);
		scanf("%d %c",&x,&c);
		int id2=getid(x,c);
		G[id1].push_back(id2);
		G[id2^1].push_back(id1^1);
	}
	scanf("%s",s+1);
	for(limit=n;limit>=0;limit--)
	{
		if(check())return 0;
	}
	puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char s[30];
int ty[30];
char ned[202];
int ls;
int len;
int n,m;
bool mark[500];
int rep[500];
vector<int>G[500];
vector<int>tp;
int op;
int getid(int x,char c)
{
	return c=='V'?(x<<1):(x<<1|1);
}
int find(int st,int Ty)
{
	for(int i=st;i<ls;i++)
		if(ty[i]==Ty)
			return i;
	return ls;
}
bool dfs(int u)
{
	if(mark[u])return 1;
	if(mark[u^1])return 0;
	int l=u>>1;
	int Ty=u>(u^1)?1:0;
	mark[u]=1;
	tp.push_back(u);
	if(l<=len)
	{
		if(ty[ned[l]-'a']!=Ty)return false;
		rep[l]=ned[l]-'a';
	}
	else
	{
		int c=find(l==len+1?(ned[l]-'a'+1):0,Ty);
		if(c==ls)return false;
		rep[l]=c;
	}
	for(int i=0;i<G[u].size();i++)
		if(!dfs(G[u][i]))
			return false;
	return true;
}
bool check()
{
	memset(mark,0,sizeof(mark));
	for(int i=1;i<=n;i++)
	{
		int c=ned[i]-'a';
		if(i<=len)
		{
			if(!dfs(i<<1|ty[c]))return false;
		}
		else
		{
			if(mark[i<<1]||mark[i<<1|1])continue;
			int a,b;
			if(i==len+1){a=find(c+1,0);b=find(c+1,1);}
			else {a=find(0,0);b=find(0,1);}
			int fid,fa;
			if(a<b)fid=i<<1,fa=a;else fid=i<<1|1,fa=b;
			if(fa==ls)return false;
			tp.clear();
			if(!dfs(fid))
			{
				for(int j=0;j<tp.size();j++)mark[tp[j]]=0;
				if(a+b-fa==ls||!dfs(fid^1))return false;
			}
		}
	}
	for(int i=1;i<=n;i++)putchar(rep[i]+'a');
	return 1;
}
int main()
{
	scanf("%s",s);
	ls=strlen(s);
	for(int i=0;i<ls;i++)ty[i]=s[i]=='V'?0:1;
	scanf("%d%d",&n,&m);
	//V:0,C:1
	for(int i=0;i<m;i++)
	{
		int x;
		char c;
		scanf("%d %c",&x,&c);
		int id1=getid(x,c);
		scanf("%d %c",&x,&c);
		int id2=getid(x,c);
		G[id1].push_back(id2);
		G[id2^1].push_back(id1^1);
	}
	scanf("%s",ned+1);
	for(len=n;len>=0;len--)
	{
		if(check())return 0;
	}
	puts("-1");
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[j])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2],fa[205],vis[205];vi e[205];
pii state[205];
bool check(int u,int rt){
    int k=d[c[u]];
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                e[rt].pb(j);
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                e[rt].pb(j-n);
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        if(!check(x,x)){
            for(int i=0;i<e[x].size();i++)c[e[x][i]]=-1;
            e[x].clear();
            return 0;
        }
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    //if(!vis[x])state[x]=mp(0,less),vis[x]=1;
    for(int i=0;i<t;i++){
        state[x].x++;
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);int m1=m;
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[j])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2];vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j,rt)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n,rt)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
                    e[x].clear();
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    //c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);int m1=m;
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[j])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2],ta,tb;vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(!ta)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j,rt)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(!tb)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n,rt)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0,ta=1;
        else type[i]=1,tb=1;
    }
    scanf("%d%d",&n,&m);int m1=m;
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k),g[k+n].pb(j+n);
            else g[j].pb(k+n),g[k].pb(j+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k),g[k+n].pb(j);
            else g[j+n].pb(k+n),g[k].pb(j);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[u])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2];vi e;
bool check(int u){
    int k=d[c[u]];e.pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e.size();j++)c[e[j]]=-1;
            e.clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[u])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2],rt;vi e[205];
bool check(int u){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    rt=x;
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e[rt].size();j++)c[e[rt][j]]=-1;
            e[rt].clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[u])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2];vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j,rt)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n,rt)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
                    e[x].clear();
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    //c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);int m1=m;
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){if(n==50&&m1==50)assert(0);else puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[u])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2];vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j,rt)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n,rt)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
                    e[x].clear();
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    //c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[j])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2];vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j,rt)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n,rt)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);int m1=m;
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k),g[k+n].pb(j+n);
            else g[j].pb(k+n),g[k].pb(j+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k),g[k+n].pb(j);
            else g[j+n].pb(k+n),g[k].pb(j);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[j])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2];vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j,rt)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n,rt)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);int m1=m;
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[j])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2],Cnt[205];vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            //cerr<<u<<" "<<c[u]<<" ";
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                e[rt].pb(j);//cerr<<j<<" "<<0<<"..\n";
                if(c[j]==-1){
                    c[j]=0;
                    Cnt[j]=1;
                }
                else Cnt[j]++;
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                e[rt].pb(j-n);//cerr<<j-n<<" 1..\n";
                if(c[j-n]==-1){
                    c[j-n]=1;
                    Cnt[j-n]=1;
                }
                else Cnt[j-n]++;
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        if(!check(x,x)){
            for(int i=0;i<e[x].size();i++){
                --Cnt[e[x][i]];
                if(Cnt[e[x][i]]==0)c[e[x][i]]=-1;
            }
            e[x].clear();
            return 0;
        }
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        for(int i=0;i<e[x].size();i++){
                --Cnt[e[x][i]];
                if(Cnt[e[x][i]]==0)c[e[x][i]]=-1;
        }
        e[x].clear();
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++){
                --Cnt[e[x][j]];
                if(Cnt[e[x][j]]==0)c[e[x][j]]=-1;
            }
            e[x].clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);int m1=m;
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <assert.h>
#include <complex>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 4005

inline void Min(int &a,int b){if(a>b)a=b;}
inline void Max(int &a,int b){if(a<b)a=b;}

int c[205],n,type[26],t;
vi g[500];
char s[205],ans[205];
int ok,cnt,low[500],dfn[500],in[500],S[500],top,p,be[500];
void tarjan(int u){
    dfn[u]=low[u]=++cnt;S[++top]=u;in[u]=1;
    for(int i=0;i<g[u].size();i++){
        int j=g[u][i];
        if(!dfn[j])tarjan(j),low[u]=min(low[u],low[j]);
        else if(in[u])low[u]=min(low[u],dfn[j]);
    }
    if(dfn[u]==low[u]){
        ++p;int j;
        do{
            j=S[top--];
            in[j]=0;be[j]=p;
        }while(j!=u);
    }
}
int d[2];vi e[205];
bool check(int u,int rt){
    int k=d[c[u]];e[rt].pb(u);
        for(int i=0;i<g[u+k].size();i++){
            int j=g[u+k][i];
            if(j<n){
                if(c[j]!=-1&&c[j]!=0)return 0;
                if(c[j]==-1){
                c[j]=0;
                if(!check(j,rt)){c[j]=-1;return 0;}
                }
            }
            else{
                if(c[j-n]!=-1&&c[j-n]!=1)return 0;
                if(c[j-n]==-1){
                c[j-n]=1;
                if(!check(j-n,rt)){c[j-n]=-1;return 0;}
                }
            }
        }
    return 1;
}
bool dfs(int x,bool less=0){
    /*if(x){
        cerr<<x<<" "<<c[x]<<" "<<c[x-1]<<" "<<ans[x-1]<<"\n";
    }*/
    if(x==n)return 1;
    if(c[x]!=-1){
        for(int i=0;i<t;i++)if(type[i]==c[x]){
            if(less){
                ans[x]=i+'a';
                if(dfs(x+1,less))return 1;
            }
            else if(i+'a'>=s[x]){
                ans[x]=i+'a';
                if(dfs(x+1,i+'a'>s[x]))return 1;
            }
        }
        return 0;
    }
    for(int i=0;i<t;i++){
        ans[x]=i+'a';
        c[x]=type[i];
        if(less||ans[x]>=s[x]){
            if(check(x,x)){
                if(dfs(x+1,less|ans[x]>s[x])){
                    //cerr<<x<<" "<<c[x]<<" "<<ans[x]<<"????\n";
                    return 1;
                }
            }
            for(int j=0;j<e[x].size();j++)c[e[x][j]]=-1;
            e[x].clear();
        }
    }
    c[x]=-1;
    return 0;
}
int main()
{
    int m,i,j,k,T,ca=0;
    scanf("%s",s);
    t=strlen(s);
    for(i=0;i<t;i++){
        if(s[i]=='V')type[i]=0;
        else type[i]=1;
    }
    scanf("%d%d",&n,&m);
    d[0]=0,d[1]=n;
    for(i=0;i<n;i++)c[i]=-1;
    while(m--){
        char s1[2],s2[2];
        scanf("%d%s%d%s",&j,s1,&k,s2);j--,k--;
        if(s1[0]=='V'){
            if(s2[0]=='V')g[j].pb(k);
            else g[j].pb(k+n);
        }
        else{
            if(s2[0]=='V')g[j+n].pb(k);
            else g[j+n].pb(k+n);
        }
    }
    scanf("%s",s);
    for(i=0;i<2*n;i++)if(dfn[i]==0)tarjan(i);
    ok=1;
    for(i=0;i<n;i++){
        if(be[i]==be[i+n]){
            ok=0;break;
        }
    }
    if(!ok){puts("-1");return 0;}
    if(!dfs(0))ok=0;
    if(!ok)puts("-1");
    else{
        ans[n]=0;puts(ans);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int n,m;
int numcar;
int tipo[26];
int quedan[27][3];

int llega[400][400];

int necesario[200];

int valorini[200];

void escribe()
{
  for (int i=0;i<n;i++)
    cout<<char(valorini[i]+'a');
  cout<<endl;
}

bool infiere(int act[200],int i)
{
  if (act[i]) {
    int ii=i;
    if (act[i]==2) ii+=n;
    for (int jj=0;jj<2*n;jj++) {
      if (llega[ii][jj]) {
	int j=jj;
	int val=1;
	if (j>=n) {
	  j-=n;
	  val=2;
	}
	if (act[j] and act[j]!=val) return false;
	act[j]=val;
      }
    }
  }
  return true;
}

bool infiere(int act[200])
{
  for (int i=0;i<n;i++) {
    if (necesario[i] and act[i] and necesario[i]!=act[i]) return false;
    if (necesario[i])
      act[i]=necesario[i];
  }
  for (int i=0;i<n;i++)
    if (not infiere(act,i))
      return false;
  return true;
}

bool sepuedemayor(int act[200],int k)
{
  for (int i=k;i<n;i++) {
    if (act[i]) {
      if (quedan[valorini[i]+1][act[i]]) return true;
      if (tipo[valorini[i]]!=act[i]) return false;
    } else {
      if (valorini[i]!=numcar-1) return true;
      act[i]=tipo[valorini[i]];
      if (not infiere(act,i)) return false;
    }
  }
  return false;
}

int act[200];
int ini[200];

int main()
{
  string car;
  cin>>car;
  numcar=int(car.size());
  int numvocales=0;
  for (int i=0;i<numcar;i++) {
    if (car[i]=='V') {
      tipo[i]=1;
      numvocales++;
    } else tipo[i]=2;
  }
  for (int i=numcar-1;i>=0;i--) {
    quedan[i][1]=quedan[i+1][1] or tipo[i]==1;
    quedan[i][2]=quedan[i+1][2] or tipo[i]==2;
  }
  cin>>n>>m;
  bool cruceVC=false,cruceCV=false;
  for (int i=0;i<2*n;i++)
    llega[i][i]=1;
  for (int i=0;i<m;i++) {
    int pos1,pos2;
    char c1,c2;
    cin>>pos1>>c1>>pos2>>c2;
    pos1--;pos2--;
    int val1=c1!='V';
    int val2=c2!='V';
    if (val1==0 and val2==1) cruceVC=true;
    if (val1==1 and val2==0) cruceCV=true;
    llega[pos1+val1*n][pos2+val2*n]=1;
    llega[pos2+(1-val2)*n][pos1+(1-val1)*n]=1;
  }
  for (int i=0;i<n;i++) {
    char c;
    cin>>c;
    valorini[i]=c-'a';
    ini[i]=tipo[valorini[i]];
  }
  if (infiere(ini)) {
    escribe();
    exit(0);
  }
  if (numvocales==0) {
    if (cruceCV) cout<<-1<<endl;
    else escribe();
    exit(0);
  }
  if (numvocales==numcar) {
    if (cruceVC) cout<<-1<<endl;
    else escribe();
    exit(0);
  }
  for (int k=0;k<2*n;k++)
    for (int i=0;i<2*n;i++)
      for (int j=0;j<2*n;j++)
	llega[i][j]=llega[i][j] or (llega[i][k] and llega[k][j]);
  for (int i=0;i<n;i++) {
    if (llega[i][i+n] and llega[i+n][i]) {
      cout<<-1<<endl;
      exit(0);
    }
    if (llega[i][i+n]) necesario[i]=2;
    else if (llega[i+n][i]) necesario[i]=1;
  }
  if (not infiere(necesario)) {
    cout<<-1<<endl;
    exit(0);
  }
  if (not sepuedemayor(necesario,0)) {
    cout<<-1<<endl;
    exit(0);
  }
  infiere(act);
  for (int i=0;i<n;i++) {
    act[i]=tipo[valorini[i]];
    if (not infiere(act) or not sepuedemayor(act,i+1)) {
      for (int j=i;j<n;j++)
	act[j]=0;
      infiere(act);
      valorini[i]++;
      for (int j=i+1;j<n;j++)
	valorini[j]=0;
      for (int j=i;j<n;j++) {
	if (act[j]) {
	  while (tipo[valorini[j]]!=act[j]) valorini[j]++;
	} else {
	  act[j]=tipo[valorini[j]];
	  infiere(act);
	}
      }
      break;
    }
  }
  escribe();
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int n,m;
int numcar;
int tipo[26];
int quedan[27][3];

int llega[400][400];

int necesario[200];

int valorini[200];

void escribe()
{
  for (int i=0;i<n;i++)
    cout<<char(valorini[i]+'a');
  cout<<endl;
}

bool infiere(int act[200],int i)
{
  if (act[i]) {
    int ii=i;
    if (act[i]==2) ii+=n;
    for (int jj=0;jj<2*n;jj++) {
      if (llega[ii][jj]) {
	int j=jj;
	int val=1;
	if (j>=n) {
	  j-=n;
	  val=2;
	}
	if (act[j] and act[j]!=val) return false;
	act[j]=val;
      }
    }
  }
  return true;
}

bool infiere(int act[200])
{
  for (int i=0;i<n;i++) {
    if (necesario[i] and act[i] and necesario[i]!=act[i]) return false;
    if (necesario[i])
      act[i]=necesario[i];
  }
  for (int i=0;i<n;i++)
    if (not infiere(act,i))
      return false;
  return true;
}

bool sepuedemayor(int act[200],int k)
{
  for (int i=k;i<n;i++) {
    if (act[i]) {
      if (quedan[valorini[i]+1][act[i]]) return true;
      if (tipo[valorini[i]]!=act[i]) return false;
    } else {
      if (valorini[i]!=numcar-1) return true;
      act[i]=tipo[valorini[i]];
      if (not infiere(act,i)) return false;
    }
  }
  return false;
}

int act[200];
int ini[200];

int main()
{
  string car;
  cin>>car;
  numcar=int(car.size());
  int numvocales=0;
  for (int i=0;i<numcar;i++) {
    if (car[i]=='V') {
      tipo[i]=1;
      numvocales++;
    } else tipo[i]=2;
  }
  for (int i=numcar-1;i>=0;i--) {
    quedan[i][1]=quedan[i+1][1] or tipo[i]==1;
    quedan[i][2]=quedan[i+1][2] or tipo[i]==2;
  }
  cin>>n>>m;
  bool cruceVC=false,cruceCV=false;
  for (int i=0;i<2*n;i++)
    llega[i][i]=1;
  for (int i=0;i<m;i++) {
    int pos1,pos2;
    char c1,c2;
    cin>>pos1>>c1>>pos2>>c2;
    pos1--;pos2--;
    int val1=c1!='V';
    int val2=c2!='V';
    if (val1==0 and val2==1) cruceVC=true;
    if (val1==1 and val2==0) cruceCV=true;
    llega[pos1+val1*n][pos2+val2*n]=1;
    llega[pos2+(1-val2)*n][pos1+(1-val1)*n]=1;
  }
  for (int i=0;i<n;i++) {
    char c;
    cin>>c;
    valorini[i]=c-'a';
    ini[i]=tipo[valorini[i]];
  }
  if (infiere(ini)) {
    escribe();
    exit(0);
  }
  if (numvocales==0) {
    if (cruceCV) cout<<-1<<endl;
    else escribe();
    exit(0);
  }
  if (numvocales==n) {
    if (cruceVC) cout<<-1<<endl;
    else escribe();
    exit(0);
  }
  for (int k=0;k<2*n;k++)
    for (int i=0;i<2*n;i++)
      for (int j=0;j<2*n;j++)
	llega[i][j]=llega[i][j] or (llega[i][k] and llega[k][j]);
  for (int i=0;i<n;i++) {
    if (llega[i][i+n] and llega[i+n][i]) {
      cout<<-1<<endl;
      exit(0);
    }
    if (llega[i][i+n]) necesario[i]=2;
    else if (llega[i+n][i]) necesario[i]=1;
  }
  if (not infiere(necesario)) {
    cout<<-1<<endl;
    exit(0);
  }
  if (not sepuedemayor(necesario,0)) {
    cout<<-1<<endl;
    exit(0);
  }
  infiere(act);
  for (int i=0;i<n;i++) {
    act[i]=tipo[valorini[i]];
    if (not infiere(act) or not sepuedemayor(act,i+1)) {
      for (int j=i;j<n;j++)
	act[j]=0;
      infiere(act);
      valorini[i]++;
      for (int j=i+1;j<n;j++)
	valorini[j]=0;
      for (int j=i;j<n;j++) {
	if (act[j]) {
	  while (tipo[valorini[j]]!=act[j]) valorini[j]++;
	} else {
	  act[j]=tipo[valorini[j]];
	  infiere(act);
	}
      }
      break;
    }
  }
  escribe();
}


#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 400 + 7;
const int M = 200 * 1000 + 13;

int n, m, k;
string s;
bool al[N];
pair<pt, pt> rules[M];

bool read () {
	static char buf[N];
	if (scanf("%s", buf) != 1)
		return false;
	k = strlen(buf);
	forn(i, k)
		al[i] = (buf[i] == 'V');
	scanf("%d%d", &n, &m);
	forn(i, m){
		int x, y;
		char c1, c2;
		scanf("%d %c %d %c", &x, &c1, &y, &c2);
		--x, --y;
		rules[i] = mp(mp(x, c1 == 'V'), mp(y, c2 == 'V'));
	}
	scanf("%s", buf);
	s = buf;
	return true;
}

string ans;

bool g[N][N];

bool used[N];
vector<int> ord;

void ts(int v){
	used[v] = true;
	forn(u, 2 * n)
		if (g[v][u] && !used[u])
			ts(u);
	ord.pb(v);
}

int comp[N];
int clr;

void dfs(int v){
	used[v] = true;
	comp[v] = clr;

	forn(u, 2 * n)
		if (g[u][v] && !used[u])
			dfs(u);
}

bool check(){
	memset(g, false, sizeof(g));

	forn(i, sz(ans)){
		int v = 2 * i + al[ans[i] - 'a'];
		g[v ^ 1][v] = true;
	}

	forn(i, m){
		int v = 2 * rules[i].x.x + rules[i].x.y;
		int u = 2 * rules[i].y.x + rules[i].y.y;
		g[v][u] = true;
		g[u ^ 1][v ^ 1] = true;
	}

	ord.clear();
	memset(used, 0, sizeof(used));
	forn(i, 2 * n) if (!used[i]) ts(i);

	reverse(all(ord));

	clr = 0;
	memset(used, 0, sizeof(used));
	forn(i, 2 * n) if (!used[ord[i]]){
		dfs(ord[i]);
		++clr;
	}

	forn(i, n)
		if (comp[2 * i] == comp[2 * i + 1])
			return false;

	return true;
}

void solve() {
	ans = s;

	if (check()){
		printf("%s\n", ans.c_str());
		return;
	}

	bool fl = false;
	for (int i = n - 1; i != -1 && i != n; i += (fl ? 1 : -1)){
		bool ov = false, oc = false;

		if (!fl) ans.pop_back();

		fore(j, (fl ? 0 : (s[i] - 'a' + 1)), k){
			if (al[j]){
				if (ov) continue;
				ov = true;
			}
			else{
				if (oc) continue;
				oc = true;
			}

			ans += ('a' + j);
			if (check()){
				fl = true;
				break;
			}
			ans.pop_back();
		}

		if (sz(ans) == n){
			printf("%s\n", ans.c_str());
			return;
		}
	}

	puts("-1");
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 405;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN], lim[MAXN], ans[MAXN];
int n, m, l, edge[MAXN][MAXN], tot, point[MAXN][2];
int timer, dfn[MAXN], low[MAXN], cnt, belong[MAXN];
int top, Stack[MAXN]; bool instack[MAXN];
void work(int pos) {
	dfn[pos] = low[pos] = ++timer;
	Stack[++top] = pos, instack[pos] = true;
	for (int i = 1; i <= tot; i++)
		if (edge[pos][i]) {
			if (dfn[i] == 0) {
				work(i);
				chkmin(low[pos], low[i]);
			} else if (instack[i]) chkmin(low[pos], dfn[i]);
		}
	if (low[pos] == dfn[pos]) {
		int tmp = Stack[top--];
		belong[tmp] = ++cnt;
		instack[tmp] = false;
		while (tmp != pos) {
			tmp = Stack[top--];
			belong[tmp] = cnt;
			instack[tmp] = false;
		}
	}
}
bool check() {
	timer = cnt = 0, memset(dfn, 0, sizeof(dfn));
	for (int i = 1; i <= tot; i++)
		if (dfn[i] == 0) work(i);
	for (int i = 1; i <= n; i++)
		if (belong[point[i][0]] == belong[point[i][1]]) return false;
	return true;
}
void limit(int pos, bool type, int d) {
	edge[point[pos][type ^ 1]][point[pos][type]] += d;
}
int main() {
	scanf("\n%s", s + 1);
	l = strlen(s + 1), read(n), read(m);
	int cnt[2] = {0, 0};
	for (int i = 1; i <= n; i++) {
		cnt[s[i] == 'V']++;
		point[i][0] = ++tot;
		point[i][1] = ++tot;
	}
	if (cnt[0] == 0) {
		for (int i = 1; i <= n; i++)
			limit(i, 1, 1);
	}
	if (cnt[1] == 0) {
		for (int i = 1; i <= n; i++)
			limit(i, 0, 1);
	}
	for (int i = 1; i <= m; i++) {
		int x, y; char tx, ty;
		scanf("%d %c %d %c", &x, &tx, &y, &ty);
		edge[point[x][tx == 'V']][point[y][ty == 'V']]++;
		edge[point[y][ty != 'V']][point[x][tx != 'V']]++;
	}
	scanf("\n%s", lim + 1);
	for (int i = 1; i <= n; i++)
		limit(i, s[lim[i] - 'a' + 1] == 'V', 1);
	if (check()) {
		printf("%s\n", lim + 1);
		return 0;
	}
	for (int i = 1; i <= n; i++)
		limit(i, s[lim[i] - 'a' + 1] == 'V', -1);
	for (int p = n; p >= 1; p--) {
		for (int i = 1; i <= p - 1; i++)
			limit(i, s[lim[i] - 'a' + 1] == 'V', 1);
		int q[2] = {l + 1, l + 1};
		for (int i = l; i >= lim[p] - 'a' + 2; i--)
			q[s[i] == 'V'] = i;
		int nxt = l + 1;
		limit(p, 0, 1);
		if (q[0] != l + 1 && check()) chkmin(nxt, q[0]);
		limit(p, 0, -1);
		limit(p, 1, 1);
		if (q[1] != l + 1 && check()) chkmin(nxt, q[1]);
		limit(p, 1, -1);
		if (nxt != l + 1) {
			for (int i = 1; i <= p - 1; i++)
				ans[i] = lim[i];
			ans[p] = nxt + 'a' - 1;
			limit(p, s[nxt] == 'V', 1);
			int r[2] = {l + 1, l + 1};
			for (int i = l; i >= 1; i--)
				r[s[i] == 'V'] = i;
			for (int i = p + 1; i <= n; i++) {
				ans[i] = l + 'a';
				limit(i, 0, 1);
				if (r[0] != l + 1 && check()) chkmin(ans[i], (char) (r[0] + 'a' - 1));
				limit(i, 0, -1);
				limit(i, 1, 1);
				if (r[1] != l + 1 && check()) chkmin(ans[i], (char) (r[1] + 'a' - 1));
				limit(i, 1, -1);
				limit(i, s[ans[i] - 'a' + 1] == 'V', 1);
			}
			printf("%s\n", ans + 1);
			return 0;
		}
		for (int i = 1; i <= p - 1; i++)
			limit(i, s[lim[i] - 'a' + 1] == 'V', -1);
	}
	puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 405;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN], lim[MAXN], ans[MAXN];
int n, m, l, edge[MAXN][MAXN], tot, point[MAXN][2];
int timer, dfn[MAXN], low[MAXN], cnt, belong[MAXN];
int top, Stack[MAXN]; bool instack[MAXN];
void work(int pos) {
	dfn[pos] = low[pos] = ++timer;
	Stack[++top] = pos, instack[pos] = true;
	for (int i = 1; i <= tot; i++)
		if (edge[pos][i]) {
			if (dfn[i] == 0) {
				work(i);
				chkmin(low[pos], low[i]);
			} else if (instack[i]) chkmin(low[pos], dfn[i]);
		}
	if (low[pos] == dfn[pos]) {
		int tmp = Stack[top--];
		belong[tmp] = ++cnt;
		instack[tmp] = false;
		while (tmp != pos) {
			tmp = Stack[top--];
			belong[tmp] = cnt;
			instack[tmp] = false;
		}
	}
}
bool check() {
	timer = cnt = 0, memset(dfn, 0, sizeof(dfn));
	for (int i = 1; i <= tot; i++)
		if (dfn[i] == 0) work(i);
	for (int i = 1; i <= n; i++)
		if (belong[point[i][0]] == belong[point[i][1]]) return false;
	return true;
}
void limit(int pos, bool type, int d) {
	edge[point[pos][type ^ 1]][point[pos][type]] += d;
}
int main() {
	scanf("\n%s", s + 1);
	l = strlen(s + 1), read(n), read(m);
	int cnt[2] = {0, 0};
	for (int i = 1; i <= l; i++)
		cnt[s[i] == 'V']++;
	for (int i = 1; i <= n; i++) {
		point[i][0] = ++tot;
		point[i][1] = ++tot;
	}
	if (cnt[0] == 0) {
		for (int i = 1; i <= n; i++)
			limit(i, 1, 1);
	}
	if (cnt[1] == 0) {
		for (int i = 1; i <= n; i++)
			limit(i, 0, 1);
	}
	for (int i = 1; i <= m; i++) {
		int x, y; char tx, ty;
		scanf("%d %c %d %c", &x, &tx, &y, &ty);
		edge[point[x][tx == 'V']][point[y][ty == 'V']]++;
		edge[point[y][ty != 'V']][point[x][tx != 'V']]++;
	}
	scanf("\n%s", lim + 1);
	for (int i = 1; i <= n; i++)
		limit(i, s[lim[i] - 'a' + 1] == 'V', 1);
	if (check()) {
		printf("%s\n", lim + 1);
		return 0;
	}
	for (int i = 1; i <= n; i++)
		limit(i, s[lim[i] - 'a' + 1] == 'V', -1);
	for (int p = n; p >= 1; p--) {
		for (int i = 1; i <= p - 1; i++)
			limit(i, s[lim[i] - 'a' + 1] == 'V', 1);
		int q[2] = {l + 1, l + 1};
		for (int i = l; i >= lim[p] - 'a' + 2; i--)
			q[s[i] == 'V'] = i;
		int nxt = l + 1;
		limit(p, 0, 1);
		if (q[0] != l + 1 && check()) chkmin(nxt, q[0]);
		limit(p, 0, -1);
		limit(p, 1, 1);
		if (q[1] != l + 1 && check()) chkmin(nxt, q[1]);
		limit(p, 1, -1);
		if (nxt != l + 1) {
			for (int i = 1; i <= p - 1; i++)
				ans[i] = lim[i];
			ans[p] = nxt + 'a' - 1;
			limit(p, s[nxt] == 'V', 1);
			int r[2] = {l + 1, l + 1};
			for (int i = l; i >= 1; i--)
				r[s[i] == 'V'] = i;
			for (int i = p + 1; i <= n; i++) {
				ans[i] = l + 'a';
				limit(i, 0, 1);
				if (r[0] != l + 1 && check()) chkmin(ans[i], (char) (r[0] + 'a' - 1));
				limit(i, 0, -1);
				limit(i, 1, 1);
				if (r[1] != l + 1 && check()) chkmin(ans[i], (char) (r[1] + 'a' - 1));
				limit(i, 1, -1);
				limit(i, s[ans[i] - 'a' + 1] == 'V', 1);
			}
			printf("%s\n", ans + 1);
			return 0;
		}
		for (int i = 1; i <= p - 1; i++)
			limit(i, s[lim[i] - 'a' + 1] == 'V', -1);
	}
	puts("-1");
	return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=420;
const ll inf=1e9+800;
const ll mod=1e9+7;
const char BIGG=('z'+1);

string typ;
string BIG;
ll l;

vector<ll> out[maxn];
vector<ll> in[maxn];

bool hast[maxn];

bool find_f(char c){
    if(c=='C'){
        return 0;
    }
    return 1;
}
void add(ll a,ll b){
    out[a^1].pb(b);
    out[b^1].pb(a);

    in[b].pb(a^1);
    in[a].pb(b^1);
}

void dfs(ll a){
    if(hast[a])return;
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        dfs(out[a][i]);
    }
}
map<string,bool> tan_opt;

bool tanaghoz(string s){
    string e=s;
    for(ll i=0;i<s.size();i++){
        e[i]=typ[(s[i]-'a')];
    }
    if(tan_opt.count(e)){
        return tan_opt[e];
    }
    fill(hast,hast+maxn,0);
    for(ll i=0;i<s.size();i++){
        dfs(i*2^typ[s[i]-'a']);
    }
    for(ll i=0;i<maxn;i++){
        if(hast[i]==1 && hast[i^1]==1){
            tan_opt[e]=1;
            return 1;
        }
    }
    tan_opt[e]=0;
    return 0;
}
void find_ans(string s,string ans){
    if((ans+BIGG)<s){
        return ;
    }
    if(tanaghoz(ans)){
        return ;
    }
    if(s.size()==ans.size()){
        cout<<ans<<endl;
        exit(0);
    }
    for(ll i=0;i<l;i++){
        find_ans(s,ans+(char)(i+'a'));
    }
    return ;
}
int main(){
    BIG+=BIGG;
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    string s;
    cin>>typ;
    l=typ.size();
    for(ll i=0;i<l;i++){
        typ[i]=find_f(typ[i]);
    }
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll pos1,pos2;
        char c1,c2;
        cin>>pos1>>c1>>pos2>>c2;
        pos1--;
        pos2--;
        c1=find_f(c1);
        c2=find_f(c2);

        add((pos1*2)^(c1^1),(pos2*2)^c2);
    }
    cin>>s;
    find_ans(s,"");
    cout<<-1;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=420;
const ll inf=1e9+800;
const ll mod=1e9+7;
const char BIGG=('z'+1);

string typ;
string BIG;
ll l;

vector<ll> out[maxn];
vector<ll> topol;
ll moa[maxn];
bool hast[maxn];

bool find_f(char c){
    if(c=='C'){
        return 0;
    }
    return 1;
}
void add(ll a,ll b){
    out[a^1].pb(b);
    out[b^1].pb(a);
}
void dfs_topol(ll a){
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        ll v=out[a][i];
        if(hast[v]==0){
            dfs_topol(v);
        }
    }
    topol.pb(a);
}
void dfs_make_moa(ll a,ll b){
    hast[a]=1;
    moa[a]=b;
    for(ll i=0;i<out[a].size();i++){
        ll v=out[a][i];
        if(hast[v]==0){
            dfs_make_moa(v,b);
        }
    }
}

void dfs(ll a){
    if(hast[a])return;
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        dfs(out[a][i]);
    }
}
bool tanaghoz(string s){
    for(ll i=0;i<s.size();i++){
        ll v=(i*2^typ[s[i]-'a']);
        out[v^1].pb(v);
    }
    fill(hast,hast+maxn,0);
    topol.clear();
    for(ll i=0;i<maxn;i++){
        if(hast[i]==0){
            dfs_topol(i);
        }
    }
    fill(hast,hast+maxn,0);
    for(ll i=0;i<maxn;i++){
        ll v=topol[i];
        if(hast[v]==0){
            dfs_make_moa(v,v);
        }
    }
    for(ll i=0;i<s.size();i++){
        ll v=(i*2^typ[s[i]-'a']);
        out[v^1].pop_back();
    }
    for(ll i=0;i<maxn;i++){
        if(moa[i]==moa[i^1]){
            return 1;
        }
    }
    return 0;
}
string s;
void find_ans(string ans){
    if((ans+BIGG)<s){
        return ;
    }
    if(tanaghoz(ans)){
        return ;
    }
    if(s.size()==ans.size()){
        cout<<ans<<endl;
        exit(0);
    }
    if(ans<s){
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        find_ans(ans+s[ans.size()]);
        for(ll i=s[ans.size()]-'a'+1;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }else{
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        for(ll i=0;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }
    return ;
}
int main(){
    BIG+=BIGG;
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>typ;
    l=typ.size();

    ll sd[2];
    sd[0]=0;
    sd[1]=0;
    for(ll i=0;i<l;i++){
        typ[i]=find_f(typ[i]);
        sd[typ[i]]++;
    }
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll pos1,pos2;
        char c1,c2;
        cin>>pos1>>c1>>pos2>>c2;
        pos1--;
        pos2--;
        c1=find_f(c1);
        c2=find_f(c2);

        add((pos1*2)^(c1^1),(pos2*2)^c2);
    }
    if(sd[0]==0 || sd[1]==0){
        if(tanaghoz(s)){
            cout<<-1;
            return 0;
        }
        cout<<s;
        return 0;
    }
    cin>>s;
    find_ans("");
    cout<<-1;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=420;
const ll inf=1e9+800;
const ll mod=1e9+7;
const char BIGG=('z'+1);

string typ;
string BIG;
ll l;

vector<ll> out[maxn];
vector<ll> in[maxn];

bool hast[maxn];

bool find_f(char c){
    if(c=='C'){
        return 0;
    }
    return 1;
}
void add(ll a,ll b){
    out[a^1].pb(b);
    out[b^1].pb(a);

    in[b].pb(a^1);
    in[a].pb(b^1);
}

void dfs(ll a){
    if(hast[a])return;
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        dfs(out[a][i]);
    }
}
map<string,bool> tan_opt;

bool tanaghoz(string s){
    string e=s;
    for(ll i=0;i<s.size();i++){
        e[i]=typ[(s[i]-'a')];
    }
    if(tan_opt.count(e)){
        return tan_opt[e];
    }
    fill(hast,hast+maxn,0);
    for(ll i=0;i<s.size();i++){
        dfs(i*2^typ[s[i]-'a']);
    }
    for(ll i=0;i<maxn;i++){
        if(hast[i]==1 && hast[i^1]==1){
            tan_opt[e]=1;
            return 1;
        }
    }
    tan_opt[e]=0;
    return 0;
}
string s;
void find_ans(string ans){
    if((ans+BIGG)<s){
        return ;
    }
    if(tanaghoz(ans)){
        return ;
    }
    if(s.size()==ans.size()){
        cout<<ans<<endl;
        exit(0);
    }
    if(ans<s){
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        find_ans(ans+s[ans.size()]);
        for(ll i=s[ans.size()]-'a'+1;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }else{
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        for(ll i=0;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }
    return ;
}
int main(){
    BIG+=BIGG;
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>typ;
    l=typ.size();

    ll sd[2];
    for(ll i=0;i<l;i++){
        typ[i]=find_f(typ[i]);
        sd[typ[i]]++;
    }
    if(sd[0]==0 || sd[1]==0){
        if(tanaghoz(s)){
            cout<<-1;
            return 0;
        }
        cout<<s;
        return 0;
    }

    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll pos1,pos2;
        char c1,c2;
        cin>>pos1>>c1>>pos2>>c2;
        pos1--;
        pos2--;
        c1=find_f(c1);
        c2=find_f(c2);

        add((pos1*2)^(c1^1),(pos2*2)^c2);
    }
    cin>>s;
    find_ans("");
    cout<<-1;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=420;
const ll inf=1e9+800;
const ll mod=1e9+7;
const char BIGG=('z'+1);

string typ;
string BIG;
ll l;

vector<ll> out[maxn];
vector<ll> in[maxn];

bool hast[maxn];

bool find_f(char c){
    if(c=='C'){
        return 0;
    }
    return 1;
}
void add(ll a,ll b){
    out[a^1].pb(b);
    out[b^1].pb(a);

    in[b].pb(a^1);
    in[a].pb(b^1);
}

void dfs(ll a){
    if(hast[a])return;
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        dfs(out[a][i]);
    }
}

map<string,bool> tan_opt;

bool tanaghoz(string s){
    string e=s;
    for(ll i=0;i<s.size();i++){
        e[i]=typ[(s[i]-'a')];
    }
    if(tan_opt.count(e)){
        return tan_opt[e];
    }
    fill(hast,hast+maxn,0);
    for(ll i=0;i<s.size();i++){
        dfs(i*2^typ[s[i]-'a']);
    }
    for(ll i=0;i<maxn;i++){
        if(hast[i]==1 && hast[i^1]==1){
            tan_opt[e]=1;
            return 1;
        }
    }
    tan_opt[e]=0;
    return 0;
}
void find_ans(string s,string ans){
    if((ans+BIGG)<s){
        return ;
    }
    if(tanaghoz(ans)){
        return ;
    }
    if(s.size()==ans.size()){
        cout<<ans<<endl;
        exit(0);
    }
    for(ll i=0;i<l;i++){
        find_ans(s,ans+(char)(i+'a'));
    }
    return ;
}
int main(){
    BIG+=BIGG;
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    string s;
    cin>>typ;
    l=typ.size();
    for(ll i=0;i<l;i++){
        typ[i]=find_f(typ[i]);
    }
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll pos1,pos2;
        char c1,c2;
        cin>>pos1>>c1>>pos2>>c2;
        pos1--;
        pos2--;
        c1=find_f(c1);
        c2=find_f(c2);

        add((pos1*2)^(c1^1),(pos2*2)^c2);
    }
    cin>>s;
    find_ans(s,"");
    cout<<-1;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=420;
const ll inf=1e9+800;
const ll mod=1e9+7;
const char BIGG=('z'+1);

string typ;
string BIG;
ll l;

vector<ll> out[maxn];
vector<ll> topol;
ll moa[maxn];
bool hast[maxn];

bool find_f(char c){
    if(c=='C'){
        return 0;
    }
    return 1;
}
void add(ll a,ll b){
    out[a^1].pb(b);
    out[b^1].pb(a);
}
void dfs_topol(ll a){
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        ll v=out[a][i];
        if(hast[v]==0){
            dfs_topol(v);
        }
    }
    topol.pb(a);
}
void dfs_make_moa(ll a,ll b){
    hast[a]=1;
    moa[a]=b;
    for(ll i=0;i<out[a].size();i++){
        ll v=out[a][i];
        if(hast[v]==0){
            dfs_make_moa(v,b);
        }
    }
}

void dfs(ll a){
    if(hast[a])return;
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        dfs(out[a][i]);
    }
}
bool tanaghoz(string s){
    for(ll i=0;i<s.size();i++){
        ll v=(i*2^typ[s[i]-'a']);
        out[v^1].pb(v);
    }
    fill(hast,hast+maxn,0);
    topol.clear();
    for(ll i=0;i<maxn;i++){
        if(hast[i]==0){
            dfs_topol(i);
        }
    }
    fill(hast,hast+maxn,0);
    for(ll i=0;i<maxn;i++){
        ll v=topol[i];
        if(hast[v]==0){
            dfs_make_moa(v,v);
        }
    }
    for(ll i=0;i<s.size();i++){
        ll v=(i*2^typ[s[i]-'a']);
        out[v^1].pop_back();
    }
    for(ll i=0;i<maxn;i++){
        if(moa[i]==moa[i^1]){
            return 1;
        }
    }
    return 0;
}
string s;
void find_ans(string ans){
    if((ans+BIGG)<s){
        return ;
    }
    if(tanaghoz(ans)){
        return ;
    }
    if(s.size()==ans.size()){
        cout<<ans<<endl;
        exit(0);
    }
    if(ans<s){
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        find_ans(ans+s[ans.size()]);
        for(ll i=s[ans.size()]-'a'+1;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }else{
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        for(ll i=0;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }
    return ;
}
int main(){
    BIG+=BIGG;
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>typ;
    l=typ.size();

    ll sd[2];
    sd[0]=0;
    sd[1]=0;
    for(ll i=0;i<l;i++){
        typ[i]=find_f(typ[i]);
        sd[typ[i]]++;
    }
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll pos1,pos2;
        char c1,c2;
        cin>>pos1>>c1>>pos2>>c2;
        pos1--;
        pos2--;
        c1=find_f(c1);
        c2=find_f(c2);

        add((pos1*2)^(c1^1),(pos2*2)^c2);
    }
    cin>>s;
    if(sd[0]==0 || sd[1]==0){
        if(tanaghoz(s)){
            cout<<-1;
            return 0;
        }
        cout<<s;
        return 0;
    }
    find_ans("");
    cout<<-1;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=420;
const ll inf=1e9+800;
const ll mod=1e9+7;

string typ;
ll l;

vector<ll> out[maxn];
vector<ll> in[maxn];
vector<ll> topol;
ll moa[maxn];
bool hast[maxn];

bool find_f(char c){
    if(c=='C'){
        return 0;
    }
    return 1;
}
void add(ll a,ll b){
    out[a^1].pb(b);
    out[b^1].pb(a);
    in[b].pb(a^1);
    in[a].pb(b^1);
    //cout<<(a^1)<<' '<<b<<endl;
    //cout<<(b^1)<<' '<<a<<endl;
}
void dfs_topol(ll a){
    hast[a]=1;
    for(ll i=0;i<out[a].size();i++){
        ll v=out[a][i];
        if(hast[v]==0){
            dfs_topol(v);
        }
    }
    topol.pb(a);
}
void dfs_make_moa(ll a,ll b){
    hast[a]=1;
    moa[a]=b;
    for(ll i=0;i<in[a].size();i++){
        ll v=in[a][i];
        if(hast[v]==0){
            dfs_make_moa(v,b);
        }
    }
}
bool tanaghoz(string s){
    for(ll i=0;i<s.size();i++){
        ll v=(i*2^typ[s[i]-'a']);
        out[v^1].pb(v);
        //cout<<(v^1)<<' '<<v<<endl;
        in[v].pb(v^1);
    }
    fill(hast,hast+maxn,0);
    topol.clear();
    for(ll i=0;i<maxn;i++){
        if(hast[i]==0){
            dfs_topol(i);
        }
    }
    fill(hast,hast+maxn,0);
    for(ll i=maxn-1;i>=0;i--){
        ll v=topol[i];
      //  cout<<v<<" ";
        if(hast[v]==0){
            dfs_make_moa(v,v);
        }
    }
    for(ll i=0;i<s.size();i++){
        ll v=(i*2^typ[s[i]-'a']);
        out[v^1].pop_back();
        in[v].pop_back();
    }/*
    for(ll i=0;i<maxn;i++){
        cout<<moa[i]<<' ';
    }*/
    for(ll i=0;i<maxn;i++){
        if(moa[i]==moa[i^1]){
            return 1;
        }
    }
    return 0;
}
string s;
void find_ans(string ans){
    if(tanaghoz(ans)){
 //       cout<<" BAD BOD "<<ans<<endl;
        return ;
    }
 //   cout<<ans<<endl;
    if(s.size()==ans.size()){
        cout<<ans<<endl;
        exit(0);
    }
    if(ans<s){
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        find_ans(ans+s[ans.size()]);
        for(ll i=s[ans.size()]-'a'+1;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }else{
        bool sd[2];
        sd[0]=0;
        sd[1]=0;
        for(ll i=0;i<l;i++){
            if(sd[typ[i]]==0){
                sd[typ[i]]=1;
                find_ans(ans+(char)(i+'a'));
            }
        }
    }
    return ;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>typ;
    l=typ.size();

    ll sd[2];
    sd[0]=0;
    sd[1]=0;
    for(ll i=0;i<l;i++){
        typ[i]=find_f(typ[i]);
        sd[typ[i]]++;
    }
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll pos1,pos2;
        char c1,c2;
        cin>>pos1>>c1>>pos2>>c2;
        pos1--;
        pos2--;
        c1=find_f(c1);
        c2=find_f(c2);

        add((pos1*2)^(c1^1),(pos2*2)^c2);
    }
    cin>>s;
    if(sd[0]==0 || sd[1]==0){
        if(tanaghoz(s)){
            cout<<-1;
            return 0;
        }
        cout<<s;
        return 0;
    }
    find_ans("");
    cout<<-1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 400, M = 8 * 200 * 199 + 400;
int *head, headbackup[N], work[N], nxt[M], to[M], nebackup, ne, n;
void init() {
	memset(head, -1, n * sizeof(head[0]));
	ne = 0;
}
void addEdge(int f, int t) {
	nxt[ne] = head[f];
	to[ne] = t;
	head[f] = ne++;
}

int dfsTime[N], low[N], nxtTime, stk[N], stkSz, ncomp, compID[N];
void sccDFS(int i) {
	dfsTime[i] = low[i] = nxtTime++;
	stk[stkSz++] = i;
	for (int k = head[i]; ~k; k = nxt[k]) {
		int j = to[k];
		if (dfsTime[j] == -1) {
			sccDFS(j);
			low[i] = min(low[i], low[j]);
		} else if (compID[j] == -1) {
			low[i] = min(low[i], low[j]);
		}
	}
	if (low[i] == dfsTime[i]) {
		do {
			compID[stk[--stkSz]] = ncomp;
		} while (stk[stkSz] != i);
		ncomp++;
	}
}
void scc() {
	memset(dfsTime, -1, n * sizeof dfsTime[0]);
	memset(compID, -1, n * sizeof compID[0]);
	nxtTime = ncomp = 0;
	for (int i = 0; i < n; ++i)
		if (!~dfsTime[i]) //==-1
			sccDFS(i);
}

#define VAR(ID) ((ID)<<1) // return node ID
#define NOTVAR(ID) (VAR(ID)|1) // return Not node ID
#define NOT(ID) ((ID)^1) // 3andi even w 3awz el odd aw el 3akss

void addOr(int v1, int v2) {
	// a|b == ~a => b && ~b => a
	addEdge(NOT(v1), v2);
	addEdge(NOT(v2), v1);
}

void addXor(int v1, int v2) {
	// a^b == a|b && ~a | ~b
	addOr(v1, v2);
	addOr(NOT(v1), NOT(v2));
}

void addImplication(int v1, int v2) {
	addOr(NOT(v1), v2);
}

int vis[N], vid;
int res[N];
void dfs(int i) {
	if (vis[i] == vid)
		return;
	vis[i] = vid;
	for (int k = head[i]; ~k; k = nxt[k]) {
		dfs(to[k]);
	}
	if (res[compID[i]] == -1) { // == -1 => it is SNK 34an ana lesa 5areg mn el recursion fa akid ana SNK
		res[compID[i]] = 1; // 1 => hay3odo na7yat el 3arosa
		res[compID[NOT(i)]] = 0; // 0 => hay3odo na7yt el 3ariis
	}
}

bool getSolution() {
	scc();
	for (int i = 0; i < (n >> 1); i++) {
		if (compID[VAR(i)] == compID[NOTVAR(i)])
			// lw ana w el not bta3y fi nafs el comp.
			return false;
	}
	vid++;
	memset(res, -1, n * sizeof res[0]); //b3tbrha kolha SNK fil awel
	for (int i = 0; i < n; i++)
		if (vis[i] != vid)
			dfs(i);
	return true;
}

char type[27], text[201];
int len, m;

void resetGraph() {
	memcpy(head, headbackup, n * sizeof head[0]);
	ne = nebackup;
}
void sabet7arf(int i, int c) {
	int v = VAR(i);
	if (type[c] == 'C')
		v = NOT(v);
	addOr(v, v);
}
bool hasNext(int &c, char t) {
	while (type[c] == t)
		c++;
	return type[c] != '\0';
}

int main() {
	///freopen("test.in", "rt", stdin);
	while (~scanf("%s", type)) {
		scanf("%d%d", &len, &m);
		n = len << 1;
		head = headbackup;
		init();
		while (m--) {
			int f, t;
			char t1, t2;
			scanf("%d %c%d %c", &f, &t1, &t, &t2);
			f--, t--;
			int v1, v2;
			v1 = VAR(f);
			v2 = VAR(t);
			if (t1 == 'C')
				v1 = NOT(v1);
			if (t2 == 'C')
				v2 = NOT(v2);
			addImplication(v1, v2);
		}
		scanf("%s", text);
		if (!getSolution()) {
			puts("-1");
			continue;
		}
		nebackup = ne;
		head = work;
		resetGraph();
		for (int i = 0; text[i]; i++) {
			int c = text[i] - 'a';
			sabet7arf(i, c);
			if (!getSolution()) {
				int t = type[c];
				if (hasNext(c, t)) {
					text[i] = c + 'a';
					for (int j = i + 1; text[j]; j++)
						text[j] = 'a';
					resetGraph();
					for (int j = 0; j < i; j++)
						sabet7arf(j, text[j] - 'a');
					i--;
					continue;
				} else {
					bool allAs = true;
					for (int j = i ; text[j]; j++)
						if (text[j] != 'a') {
							allAs = 0;
							break;
						}
					while (--i >= 0) {
						c = text[i] - 'a';
						if (allAs) {
							if (hasNext(c, type[c]))
								break;
						} else {
							if(type[c+1])
							{
								c++;
								break;
							}
						}
					}

					if (i == -1) {
						puts("-1");
						goto nxtCase;
					}
					text[i] = c + 'a';
					for (int j = i + 1; text[j]; j++)
						text[j] = 'a';
					resetGraph();
					for (int j = 0; j < i; j++)
						sabet7arf(j, text[j] - 'a');
					i--;
					continue;
				}
			}
		}
		puts(text);
		nxtCase: ;
	}
}


#include <bits/stdc++.h>
using namespace std;
const int N = 400, M = 8 * 200 * 199 + 400;
int *head, headbackup[N], work[N], nxt[M], to[M], nebackup, ne, n;
void init() {
	memset(head, -1, n * sizeof(head[0]));
	ne = 0;
}
void addEdge(int f, int t) {
	nxt[ne] = head[f];
	to[ne] = t;
	head[f] = ne++;
}

int dfsTime[N], low[N], nxtTime, stk[N], stkSz, ncomp, compID[N];
void sccDFS(int i) {
	dfsTime[i] = low[i] = nxtTime++;
	stk[stkSz++] = i;
	for (int k = head[i]; ~k; k = nxt[k]) {
		int j = to[k];
		if (dfsTime[j] == -1) {
			sccDFS(j);
			low[i] = min(low[i], low[j]);
		} else if (compID[j] == -1) {
			low[i] = min(low[i], low[j]);
		}
	}
	if (low[i] == dfsTime[i]) {
		do {
			compID[stk[--stkSz]] = ncomp;
		} while (stk[stkSz] != i);
		ncomp++;
	}
}
void scc() {
	memset(dfsTime, -1, n * sizeof dfsTime[0]);
	memset(compID, -1, n * sizeof compID[0]);
	nxtTime = ncomp = 0;
	for (int i = 0; i < n; ++i)
		if (!~dfsTime[i]) //==-1
			sccDFS(i);
}

#define VAR(ID) ((ID)<<1) // return node ID
#define NOTVAR(ID) (VAR(ID)|1) // return Not node ID
#define NOT(ID) ((ID)^1) // 3andi even w 3awz el odd aw el 3akss

void addOr(int v1, int v2) {
	// a|b == ~a => b && ~b => a
	addEdge(NOT(v1), v2);
	addEdge(NOT(v2), v1);
}

void addXor(int v1, int v2) {
	// a^b == a|b && ~a | ~b
	addOr(v1, v2);
	addOr(NOT(v1), NOT(v2));
}

void addImplication(int v1, int v2) {
	addOr(NOT(v1), v2);
}

int vis[N], vid;
int res[N];
void dfs(int i) {
	if (vis[i] == vid)
		return;
	vis[i] = vid;
	for (int k = head[i]; ~k; k = nxt[k]) {
		dfs(to[k]);
	}
	if (res[compID[i]] == -1) { // == -1 => it is SNK 34an ana lesa 5areg mn el recursion fa akid ana SNK
		res[compID[i]] = 1; // 1 => hay3odo na7yat el 3arosa
		res[compID[NOT(i)]] = 0; // 0 => hay3odo na7yt el 3ariis
	}
}

bool getSolution() {
	scc();
	for (int i = 0; i < (n >> 1); i++) {
		if (compID[VAR(i)] == compID[NOTVAR(i)])
			// lw ana w el not bta3y fi nafs el comp.
			return false;
	}
	vid++;
	memset(res, -1, n * sizeof res[0]); //b3tbrha kolha SNK fil awel
	for (int i = 0; i < n; i++)
		if (vis[i] != vid)
			dfs(i);
	return true;
}

char type[27], text[201];
int len, m;

void resetGraph() {
	memcpy(head, headbackup, n * sizeof head[0]);
	ne = nebackup;
}
void sabet7arf(int i, int c) {
	int v = VAR(i);
	if (type[c] == 'C')
		v = NOT(v);
	addOr(v, v);
}
bool hasNext(int &c, char t) {
	while (type[c] == t)
		c++;
	return type[c] != '\0';
}

int main() {
	//freopen("test.in", "rt", stdin);
	while (~scanf("%s", type)) {
		scanf("%d%d", &len, &m);
		n = len << 1;
		head = headbackup;
		init();
		while (m--) {
			int f, t;
			char t1, t2;
			scanf("%d %c%d %c", &f, &t1, &t, &t2);
			f--, t--;
			int v1, v2;
			v1 = VAR(f);
			v2 = VAR(t);
			if (t1 == 'C')
				v1 = NOT(v1);
			if (t2 == 'C')
				v2 = NOT(v2);
			addImplication(v1, v2);
		}
		scanf("%s", text);
		if (!getSolution()) {
			puts("-1");
			continue;
		}
		nebackup = ne;
		head = work;
		resetGraph();
		for (int i = 0; text[i]; i++) {
			int c = text[i] - 'a';
			sabet7arf(i, c);
			if (!getSolution()) {
				int t = type[c];
				if (hasNext(c, t)) {
					text[i] = c + 'a';
					for (int j = i + 1; text[j]; j++)
						text[j] = 'a';
					resetGraph();
					for (int j = 0; j < i; j++)
						sabet7arf(j, text[j] - 'a');
					i--;
					continue;
				} else {
					while (--i >= 0 && type[text[i] - 'a' + 1] == '\0')
						;
					if (i == -1) {
						puts("-1");
						goto nxtCase;
					}
					text[i]++;
					for (int j = i + 1; text[j]; j++)
						text[j] = 'a';
					resetGraph();
					for (int j = 0; j < i; j++)
						sabet7arf(j, text[j] - 'a');
					i--;
					continue;
				}
			}
		}
		puts(text);
		nxtCase: ;
	}
}