#include <bits/stdc++.h>   using namespace std;   const int maxn = 500;   const int maxm = 500000 + 10;   struct Edge {     int next, v;     Edge() {}     Edge(int next, int v) : next(next), v(v) {}   } e[maxm << 1];   int n, m, timer, num, len;   int head[maxm], cnt;   int dfn[maxn], low[maxn], belo[maxn];   bool inst[maxn], used[maxn];   int st[maxm], top, q[maxm], front, tail;   char org[27], s[maxn], ans[maxn], res[maxn];   int val[128];   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   inline void AddEdge(int u, int v) {     e[++cnt] = Edge(head[u], v);     head[u] = cnt;   }   void tarjan(int u) {     dfn[u] = low[u] = ++timer;     st[++top] = u;     inst[u] = 1;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].v;       if (!dfn[v]) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (inst[v])         low[u] = min(low[u], dfn[v]);     }     if (dfn[u] == low[u]) {       num++;       int v;       do {         v = st[top--];         belo[v] = num;         inst[v] = 0;       } while (u != v);     }   }   inline bool judge(int tot) {     for (int i = 2; i <= tot; i++)       if (!dfn[i]) tarjan(i);     for (int i = 2; i < tot; i += 2)       if (belo[i] == belo[i + 1]) return 0;     return 1;   }   inline char find(int pos, char ch) {     for (int i = pos + 1; i < len; i++)       if (org[i] == ch) return  a  + i;     return -1;   }   int main() {     scanf( %s , org);     len = strlen(org);     for (int i = 0; i < len; i++)       if (org[i] ==  C ) val[ a  + i] = 1;     n = read(), m = read();     char op1[10], op2[10];     int x, y;     while (m--) {       x = read(), scanf( %s , op1);       y = read(), scanf( %s , op2);       x = x << 1 | (op1[0] ==  C );       y = y << 1 | (op2[0] ==  C );       AddEdge(x, y);       AddEdge(y ^ 1, x ^ 1);     }     scanf( %s , s + 1);     if (!judge(n << 1 | 1)) {       puts( -1 );       return 0;     }     bool exis = 0;     res[1] = -1;     for (int pos = n + 1; pos >= 1; pos--) {       for (int a = pos << 1; a <= (pos << 1 | 1); a++) {         strcpy(ans + 1, s + 1);         if (pos <= n) {           char tp = find(s[pos] -  a , a & 1 ?  V  :  C );           if (tp == -1) continue;           ans[pos] = tp;         }         for (int i = pos + 1; i <= n; i++) ans[i] =  a ;         bool flag = 1;         memset(used, 0, sizeof(used));         for (int i = 1; i <= n && flag; i++) {           x = i << 1 | val[ans[i]];           if (used[x]) continue;           used[x] = 1;           front = tail = 0;           q[++tail] = x;           while (front != tail) {             x = q[++front];             used[x] = 1;             if (used[x ^ 1]) {               flag = 0;               break;             }             if ((x >> 1) <= pos && val[ans[x >> 1]] != (x & 1)) {               flag = 0;               break;             }             if ((x >> 1) > pos) {               char tp = find(-1, x & 1 ?  C  :  V );               if (tp == -1) {                 flag = 0;                 break;               }               ans[x >> 1] = tp;             }             for (int j = head[x]; j; j = e[j].next) {               int v = e[j].v;               if (!used[v]) {                 used[v] = 1;                 q[++tail] = v;               }             }           }         }         if (!flag) continue;         exis = 1;         if (res[1] == -1)           strcpy(res + 1, ans + 1);         else if (strcmp(res + 1, ans + 1) > 0)           strcpy(res + 1, ans + 1);       }       if (exis) break;     }     if (exis)       puts(res + 1);     else       puts( -1 );     return 0;   }