#include <bits/stdc++.h>
using namespace std;
const int N = 205;
char s[N], t[N];
bool g[N << 1][N << 1], vis[N << 1];
int f[30], h[30][2], a[N], n, m, k, p1, p2;
bool check(int k) {
  for (int i = 0; i < n << 1; ++i) vis[i] = false;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < (n << 1); ++j) {
      if (!g[i << 1 | f[a[i]]][j]) continue;
      if (vis[j ^ 1]) return false;
      vis[j] = true;
    }
    s[i] = 'a' + a[i];
  }
  for (int i = k; i < n; ++i) {
    bool flag = true;
    int x, y;
    if (i == k) {
      x = min(h[a[i] + 1][0], h[a[i] + 1][1]);
      y = max(h[a[i] + 1][0], h[a[i] + 1][1]);
    } else {
      x = min(h[0][0], h[0][1]);
      y = max(h[0][0], h[0][1]);
    }
    if (x == N) return false;
    for (int j = 0; j < (n << 1); ++j) {
      if (!g[i << 1 | f[x]][j]) continue;
      if (vis[j ^ 1] || g[i << 1 | f[x]][j ^ 1]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int j = 0; j < (n << 1); ++j) {
        if (!g[i << 1 | f[x]][j]) continue;
        vis[j] = true;
      }
      s[i] = 'a' + x;
      continue;
    }
    if (y == N) return false;
    flag = true;
    for (int j = 0; j < (n << 1); ++j) {
      if (!g[i << 1 | f[y]][j]) continue;
      if (vis[j ^ 1] || g[i << 1 | f[y]][j ^ 1]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int j = 0; j < (n << 1); ++j) {
        if (!g[i << 1 | f[y]][j]) continue;
        vis[j] = true;
      }
      s[i] = 'a' + y;
      continue;
    }
    return false;
  }
  return true;
}
bool solve() {
  for (int i = 0; i < (n << 1); ++i) g[i][i] = true;
  for (int k = 0; k < (n << 1); ++k)
    for (int i = 0; i < (n << 1); ++i)
      for (int j = 0; j < (n << 1); ++j) g[i][j] |= g[i][k] & g[k][j];
  for (int i = n; i >= 0; --i) {
    if (check(i)) return true;
  }
  return false;
}
int main() {
  scanf("%s", s);
  k = strlen(s);
  for (int i = 0; i < k; ++i) f[i] = s[i] == 'V';
  scanf("%d %d", &n, &m);
  while (m--) {
    scanf("%d %s %d %s", &p1, s, &p2, t);
    p1--;
    p2--;
    g[p1 << 1 | (s[0] == 'V')][p2 << 1 | (t[0] == 'V')] = true;
    g[p2 << 1 | (t[0] == 'C')][p1 << 1 | (s[0] == 'C')] = true;
  }
  scanf("%s", s);
  for (int i = 0; i < n; ++i) a[i] = s[i] - 'a';
  h[k][0] = h[k][1] = N;
  for (int i = k - 1; i >= 0; --i) {
    h[i][0] = h[i + 1][0];
    h[i][1] = h[i + 1][1];
    h[i][f[i]] = i;
  }
  if (solve())
    printf("%s\n", s);
  else
    printf("-1\n");
}
