#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
template <typename T>
inline void MIN(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void MAX(T &a, T b) {
  if (b > a) a = b;
}
char col[456];
int l;
int n, m;
struct edge {
  int nxt, to;
} e[341000];
int head[456], ecnt;
inline void addedge(int from, int to) {
  e[++ecnt] = (edge){head[from], to};
  head[from] = ecnt;
}
char s[456];
int ss[456], top;
int oth[456];
bool vis[456];
int cho[456];
int stk[456], stop;
inline void chk() {
  puts("");
  puts("check : ");
  for (int i = 1; i <= n + n; ++i) printf("cho[%d] = %d\n", i, cho[i]);
  puts("");
}
bool dfs(int cur) {
  if (vis[oth[cur]]) return false;
  if (vis[cur]) return true;
  if (cho[cur] == 0) return false;
  vis[cur] = true;
  stk[++stop] = cur;
  for (int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (!dfs(to)) return false;
  }
  return true;
}
inline bool Check() {
  memset(vis, 0, sizeof(vis));
  memset(cho, -1, sizeof(cho));
  for (int i = 1; i <= top; ++i)
    if (col[ss[i]] == 'C')
      cho[i + n] = 1, cho[i] = 0;
    else
      cho[i] = 1, cho[i + n] = 0;
  for (int i = 1; i <= n + n; ++i)
    if (!vis[i] && !vis[oth[i]]) {
      stop = 0;
      if (!dfs(i)) {
        while (stop) vis[i] = false, --stop;
        if (!dfs(oth[i])) return false;
      }
    }
  return true;
}
inline void work() {
  for (int i = 1; i <= n; ++i) oth[i] = i + n, oth[i + n] = i;
  bool flag = true;
  for (int i = 1; i <= n; ++i) {
    int cur = col[s[i] - 'a'] == 'C' ? i + n : i;
    for (int j = head[cur]; j; j = e[j].nxt) {
      int to = e[j].to;
      if (to > n) {
        if (col[s[to - n] - 'a'] == 'V') {
          flag = false;
          break;
        }
      } else {
        if (col[s[to] - 'a'] == 'C') {
          flag = false;
          break;
        }
      }
    }
    if (flag == false) break;
  }
  if (flag) {
    puts(s + 1);
    return;
  }
  int canp, tp, nw = n;
  for (int i = n; i; --i) {
    nw = i;
    int fstV = -1, fstC = -1;
    for (int j = l - 1; j > s[i] - 'a'; --j) {
      if (col[j] == 'C')
        fstC = j;
      else
        fstV = j;
    }
    canp = 100, tp = -1;
    if (~fstC) {
      for (int j = 1; j < i; ++j) ss[j] = s[j] - 'a';
      ss[i] = fstC;
      top = i;
      if (Check()) MIN(canp, fstC), tp = 1;
    }
    if (~fstV) {
      for (int j = 1; j < i; ++j) ss[j] = s[j] - 'a';
      ss[i] = fstV;
      top = i;
      if (Check()) MIN(canp, fstV), tp = 0;
    }
    if (~tp) break;
  }
  if (tp == -1) {
    puts("-1");
    return;
  }
  ss[nw] = canp;
  int fstV = -1, fstC = -1;
  for (int j = l - 1; ~j; --j) {
    if (col[j] == 'C')
      fstC = j;
    else
      fstV = j;
  }
  for (int i = nw + 1; i <= n; ++i) {
    if (fstC < fstV) {
      ss[i] = fstC;
      top = i;
      if (Check())
        ss[i] = fstC;
      else
        ss[i] = fstV;
    } else {
      ss[i] = fstV;
      top = i;
      if (Check())
        ss[i] = fstV;
      else
        ss[i] = fstC;
    }
  }
  for (int i = 1; i <= n; ++i) {
    putchar('a' + ss[i]);
  }
  puts("");
}
int main() {
  scanf("%s", col);
  l = strlen(col);
  int cntc = 0, cntv = 0;
  for (int i = 0; i < l; ++i) {
    if (col[i] == 'C')
      ++cntc;
    else
      ++cntv;
  }
  read(n), read(m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    char tpu[3], tpv[3];
    read(u);
    scanf("%s", tpu);
    read(v);
    scanf("%s", tpv);
    if (cntc == l && tpu[0] == 'C' && tpv[0] == 'V') {
      puts("-1");
      return 0;
    }
    if (cntv == l && tpu[0] == 'V' && tpv[0] == 'C') {
      puts("-1");
      return 0;
    }
    int tu = tpu[0] == 'C', tv = tpv[0] == 'C';
    addedge(u + tu * n, v + tv * n);
    addedge(v + (tv ^ 1) * n, u + (tu ^ 1) * n);
  }
  scanf("%s", s + 1);
  work();
  return 0;
}
