#include <bits/stdc++.h>
using namespace std;
const int N = 555;
const int M = 4 * N * (N - 1);
inline int IN() {
  char ch;
  (ch = getchar());
  int f = 0, x = 0;
  for (; ((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    ;
  if (ch == '-') f = 1, (ch = getchar());
  for (; !((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    x = x * 10 + ch - '0';
  return (f) ? (-x) : (x);
}
char s[N];
int st[N], dfn[N], low[N], In[N], stk[N], top, dex, scc, B[N];
int l, n, m, a[N], id[N][2], cnt, Tim, h[15], ans[N];
vector<int> E[N], _E[N], _[N], Z;
void addedge(int u, int v) { E[u].push_back(v); }
void ban(int x, int y) { addedge(id[x][y], id[x][y ^ 1]); }
void tarjan(int x) {
  low[x] = dfn[x] = ++dex;
  In[stk[++top] = x] = 1;
  for (__typeof(*E[x].begin()) v : E[x]) {
    if (!dfn[v]) {
      tarjan(v);
      low[x] = min(low[x], low[v]);
    } else if (In[v])
      low[x] = min(low[x], dfn[v]);
  }
  if (low[x] == dfn[x]) {
    int p;
    ++scc;
    do {
      p = stk[top];
      B[p] = scc;
      --top;
      In[p] = 0;
    } while (p ^ x);
  }
}
bool judge() {
  for (int i = (int)1; i <= (int)cnt; i++)
    dfn[i] = low[i] = In[i] = stk[i] = B[i] = 0;
  dex = top = scc = 0;
  for (int i = (int)1; i <= (int)cnt; i++)
    if (!dfn[i]) tarjan(i);
  for (int i = (int)1; i <= (int)n; i++)
    if (B[id[i][0]] == B[id[i][1]]) return false;
  return true;
}
void gou(int x) {
  for (int i = (int)1; i <= (int)x; i++) ans[i] = st[i];
  for (int i = (int)x + 1; i <= (int)n; i++) {
    ++Tim;
    for (int j = (int)1; j <= (int)l; j++) {
      if (h[a[j]] == Tim) continue;
      h[a[j]] = Tim;
      for (int k = (int)1; k <= (int)cnt; k++) _[k] = E[k];
      ban(i, a[j] ^ 1);
      if (judge()) {
        ans[i] = j;
        break;
      }
      for (int k = (int)1; k <= (int)cnt; k++) E[k] = _[k];
    }
  }
}
void print() {
  if (!ans[1]) {
    puts("-1");
    return;
  }
  for (int i = (int)1; i <= (int)n; i++) printf("%c", ans[i] + 'a' - 1);
  puts("");
}
int main() {
  scanf("%s", s + 1);
  l = strlen(s + 1);
  for (int i = (int)1; i <= (int)l; i++) a[i] = (s[i] == 'V');
  n = IN(), m = IN();
  for (int i = (int)1; i <= (int)n; i++)
    for (int j = (int)0; j <= (int)1; j++) id[i][j] = ++cnt;
  for (int i = (int)1; i <= (int)m; i++) {
    char ch;
    int u = IN(), tu;
    (ch = getchar());
    tu = (ch == 'V');
    int v = IN(), tv;
    (ch = getchar());
    tv = (ch == 'V');
    addedge(id[u][tu], id[v][tv]);
    addedge(id[v][tv ^ 1], id[u][tu ^ 1]);
  }
  bool flag;
  flag = 0;
  for (int i = (int)1; i <= (int)l; i++)
    if (a[i]) flag = 1;
  if (!flag)
    for (int i = (int)1; i <= (int)n; i++) ban(i, 1);
  flag = 0;
  for (int i = (int)1; i <= (int)l; i++)
    if (!a[i]) flag = 1;
  if (!flag)
    for (int i = (int)1; i <= (int)n; i++) ban(i, 0);
  scanf("%s", s + 1);
  for (int i = (int)1; i <= (int)n; i++) st[i] = s[i] - 'a' + 1;
  for (int i = (int)n; i >= (int)1; i--) {
    int A = s[i] - 'a' + 1 + (i < n);
    ++Tim;
    for (int j = (int)1; j <= (int)cnt; j++) _E[j] = E[j];
    for (int j = (int)A; j <= (int)l; j++) {
      if (h[a[j]] == Tim) continue;
      h[a[j]] = Tim;
      st[i] = j;
      for (int k = (int)1; k <= (int)cnt; k++) E[k] = _E[k];
      for (int k = (int)1; k <= (int)i; k++) ban(k, a[st[k]] ^ 1);
      if (judge()) {
        gou(i);
        print();
        exit(0);
      }
    }
    for (int j = (int)1; j <= (int)cnt; j++) E[j] = _E[j];
  }
  puts("-1");
  return 0;
}
