#include <bits/stdc++.h>
using namespace std;
const int N = 405;
int n, m, l, vis[2];
char t[30], p[2], q[2], str[N], ans[N];
bitset<N> g[N];
int chk(char x) { return t[x - 'a'] == 'V'; }
void dfs(int x, int y) {
  if (x == n) {
    printf("%s", ans);
    exit(0);
  }
  int vow = 1, con = 1;
  for (int i = 0; i < x; ++i) {
    vow &= !g[i << 1 | chk(ans[i])][x << 1];
    vow &= !g[x << 1 | 1][i << 1 | (chk(ans[i]) ^ 1)];
    con &= !g[i << 1 | chk(ans[i])][x << 1 | 1];
    con &= !g[x << 1][i << 1 | (chk(ans[i]) ^ 1)];
  }
  for (char i = y ? 'a' : str[x]; i < 'a' + l; ++i)
    if ((chk(i) && vow) || (!chk(i) && con))
      ans[x] = i, dfs(x + 1, y | (ans[x] > str[x]));
}
int main() {
  scanf("%s%d%d", t, &n, &m);
  l = strlen(t);
  for (int i = 0; i < l; ++i) vis[t[i] == 'V'] = 1;
  if (!vis[0] || !vis[1])
    for (int i = 0; i < n; ++i) g[i << 1 | vis[0]][i << 1 | (vis[0] ^ 1)] = 1;
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%s%d%s", &x, p, &y, q);
    x = x - 1 << 1 | (p[0] == 'V');
    y = y - 1 << 1 | (q[0] == 'V');
    g[x][y] = g[y ^ 1][x ^ 1] = 1;
  }
  for (int i = 0; i < n + n; ++i) g[i][i] = 1;
  for (int k = 0; k < n + n; ++k)
    for (int i = 0; i < n + n; ++i)
      if (g[i][k]) g[i] |= g[k];
  for (int i = 0; i < n + n; ++i)
    if (g[i][i ^ 1] && g[i ^ 1][i]) return puts("-1"), 0;
  scanf("%s", str);
  dfs(0, 0);
  puts("-1");
  return 0;
}
