#include<bits/stdc++.h>
using namespace std;
inline bool id(const char ch) {
return ch>='0'&&ch<='9';
}
inline int read(void) {
int s=0,f=0;
char ch=getchar();
while(!id(ch)) f=(ch=='-'),ch=getchar();
while(id(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
return f?-s:s;
}
const int MAXN=1e5+10;
int n,d,m,tot,hd[MAXN],ar[MAXN],in[MAXN],low[MAXN],dfn[MAXN],col[MAXN],dfns,cols;
struct Rule {
int posa,posb,tpea,tpeb;
}r[MAXN];
struct Edge {
int to,nxt;
}edge[MAXN<<2];
inline void add_edge(const int x,const int y) {
edge[++tot]=Edge{y,hd[x]},hd[x]=tot;
return;
}
string S;
inline int frst(const int lim,const int k) {
if(k==1) return 0;
if(k==3) return n;
if(lim==3&&k==2) return n;
return 0;
}
inline char put(const int lim,const int k) {
if(lim==1) return (k==1)?'B':'C';
if(lim==2) return (k==1)?'A':'C';
if(lim==3) return (k==1)?'A':'B';
}
stack<int>st;
void tarjan(const int u) {
in[u]=1,dfn[u]=low[u]=++dfns,st.push(u);
for(int i=hd[u];i;i=edge[i].nxt) {
int to=edge[i].to;
if(!dfn[to]) tarjan(to),low[u]=min(low[u],low[to]);
else if(in[to]) low[u]=min(low[u],dfn[to]);
}
if(low[u]==dfn[u]) {
++cols;
while(st.top()!=u) in[st.top()]=0,col[st.top()]=cols,st.pop();
in[u]=0,col[u]=cols,st.pop();
}
return;
}
inline void check(void) {
tot=0,memset(hd,0,sizeof(hd));
for(int i=1;i<=m;i++) {
if(ar[r[i].posa]==r[i].tpea||ar[r[i].posb]==r[i].tpeb) continue;
add_edge(frst(ar[r[i].posa],r[i].tpea)+r[i].posa,frst(ar[r[i].posb],r[i].tpeb)+r[i].posb);
add_edge(n-frst(ar[r[i].posb],r[i].tpeb)+r[i].posb,n-frst(ar[r[i].posa],r[i].tpea)+r[i].posa);
}
memset(col,0,sizeof(col)),dfns=0,cols=0,memset(dfn,0,sizeof(dfn)),memset(low,0,sizeof(low)),memset(in,0,sizeof(in));
for(int i=1;i<=n+n;i++) if(!col[i]) tarjan(i);
for(int i=1;i<=n;i++) if(col[i]==col[i+n]) return;
for(int i=1;i<=n;i++) printf("%c",put(ar[i],col[i]<col[i+n]));
exit(0);
}
void dfs(const int dep) {
if(dep>n) return check(),void();
if(S[dep]=='x') {
ar[dep]=1,dfs(dep+1);
ar[dep]=2,dfs(dep+1);
}
else ar[dep]=S[dep]-'a'+1,dfs(dep+1);
return ;
}
int main() {
n=read(),d=read();
cin>>S;
S="$"+S,m=read();
for(int i=1;i<=m;i++) {
int a,b;
char c,d;
a=read();
cin>>c;
b=read();
cin>>d;
r[i]=Rule{a,b,c-'A'+1,d-'A'+1};
}
dfs(1);
printf("-1");
return 0;
}