#include <bits/stdc++.h>
using namespace std;
const int N = 405, M1 = 543267891, M2 = 542798121;
map<long long, int> Map;
char ss[N], ans[N], s[N], s1[2], s2[2];
int n, m, x, y, flag[N][N], len;
bitset<N> a[N];
void jb(int x, int y) { a[x][y] = 1; }
int get(int x, int y) { return x * 2 + y - 1; }
long long hash2(int x) {
  long long v1 = 0, v2 = 0;
  for (int i = x; i <= n; i++) {
    v1 = (v1 * 5437981 + 5431 + flag[x][i]) % M1;
    v2 = (v2 * 5432879 + 1323 + flag[x][i]) % M2;
  }
  return v1 * 54327901 + v2;
}
void dfs(int x, int y) {
  if (x > n) {
    puts(ans + 1);
    exit(0);
  }
  if (y) {
    long long v = hash2(x);
    if (Map.count(x)) return;
    Map[x] = 1;
  }
  int VV[N];
  for (int i = 1; i <= n; i++) VV[i] = flag[x][i];
  for (int i = y == 0 ? ss[x] : 'a'; i < len + 'a'; i++)
    if (!VV[x] || (VV[x] & (1 << (s[i - 'a'] == 'V')))) {
      int p = get(x, s[i - 'a'] == 'V'), fflag = 1;
      for (int j = 1; j <= n; j++) flag[x + 1][j] = VV[j];
      for (int j = 1; j <= 2 * n; j++)
        if (a[p][j]) {
          if (((flag[x + 1][(j + 1) >> 1] |= 1 << (!(j & 1))) & 3) == 3) {
            fflag = 0;
            break;
          }
        }
      if (!fflag) continue;
      ans[x] = i;
      dfs(x + 1, y | (i > ss[x]));
    }
}
int main() {
  scanf("%s", s);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%s%d%s", &x, &s1, &y, &s2);
    jb(get(x, s1[0] == 'V'), get(y, s2[0] == 'V'));
    jb(get(y, s2[0] == 'C'), get(x, s1[0] == 'C'));
  }
  scanf("%s", ss + 1);
  len = strlen(s);
  for (int i = 1; i <= n * 2; i++) a[i][i] = 1;
  for (int i = 1; i <= n * 2; i++)
    for (int j = 1; j <= n * 2; j++)
      if (a[j][i]) a[j] |= a[i];
  dfs(1, 0);
  puts("-1");
  return 0;
}
