#include <bits/stdc++.h>
const int N = 205;
const int L = 30;
char s[N];
int n, m, l, a[L], mn[L][2], vis[N << 1], rp[256];
std::vector<int> e[N << 1];
inline void add_edge(int u1, int p1, int u2, int p2) {
  int x = u1 << 1 | p1, y = u2 << 1 | p2;
  e[x].push_back(y);
  e[y ^ 1].push_back(x ^ 1);
}
bool dfs(int u) {
  if (vis[u ^ 1]) return false;
  vis[u] = 1;
  for (int i = 0; i < (int)e[u].size(); ++i) {
    int v = e[u][i];
    if (!vis[v] && !dfs(v)) return false;
  }
  return true;
}
inline bool ck(int j) {
  for (int i = 0; i < 2 * n; ++i) vis[i] = 0;
  for (int i = 0; i <= j; ++i)
    if (!dfs(i << 1 | a[s[i] - 'a'])) return false;
  for (int i = j + 1; i < n; ++i) {
    if (mn[0][0] < l && vis[i << 1])
      s[i] = mn[0][0] + 'a';
    else if (mn[0][1] < l && vis[i << 1 | 1])
      s[i] = mn[0][1] + 'a';
    else {
      int x = mn[0][0], y = mn[0][1];
      if (x > y) std::swap(x, y);
      if (x < l && dfs(i << 1 | a[x]))
        s[i] = x + 'a';
      else if (y < l && dfs(i << 1 | a[y]))
        s[i] = y + 'a';
      else
        return false;
    }
  }
  return true;
}
int main() {
  scanf("%s", s);
  l = strlen(s);
  rp['V'] = 0;
  rp['C'] = 1;
  mn[l][0] = mn[l][1] = l;
  for (int i = l - 1, tmp[2] = {l, l}; i >= 0; --i) {
    tmp[a[i] = rp[(int)s[i]]] = i;
    mn[i][0] = tmp[0];
    mn[i][1] = tmp[1];
  }
  scanf("%d%d", &n, &m);
  static char s1[5], s2[5];
  for (int i = 1, p1, p2; i <= m; ++i) {
    scanf("%d%s%d%s", &p1, s1, &p2, s2);
    add_edge(--p1, rp[(int)s1[0]], --p2, rp[(int)s2[0]]);
  }
  scanf("%s", s);
  if (ck(n - 1)) return printf("%s\n", s), 0;
  for (int i = n - 1; i >= 0; --i) {
    int c = s[i] - 'a', x = mn[c + 1][0], y = mn[c + 1][1];
    if (x > y) std::swap(x, y);
    if (x < l) {
      s[i] = x + 'a';
      if (ck(i)) return printf("%s\n", s), 0;
    }
    if (y < l) {
      s[i] = y + 'a';
      if (ck(i)) return printf("%s\n", s), 0;
    }
  }
  return puts("-1"), 0;
}
