#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 4;
vector<vector<int> > g;
int n, m;
int L;
int Not(int u) {
  if (u < L) return u + L;
  return u - L;
}
void addEdge(int u, int v) {
  g[Not(u)].push_back(v);
  g[Not(v)].push_back(u);
}
vector<int> S;
int comp[N], low[N], idx[N], dfs, cmp;
bool vis[N];
void DFS(int u) {
  idx[u] = low[u] = ++dfs;
  vis[u] = true;
  S.push_back(u);
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (!low[v]) DFS(v);
    if (vis[v]) low[u] = min(low[u], low[v]);
  }
  if (low[u] == idx[u]) {
    while (true) {
      int v = S.back();
      S.pop_back();
      vis[v] = false;
      comp[v] = cmp;
      if (u == v) break;
    }
    ++cmp;
  }
}
bool check() {
  memset(low, 0, sizeof(low));
  dfs = cmp = 0;
  for (int i = 0; i < g.size(); ++i)
    if (!low[i]) DFS(i);
  for (int i = 0; i < L; ++i)
    if (comp[i] == comp[Not(i)]) return false;
  return true;
}
int main() {
  string is;
  cin >> is;
  vector<char> ch[2];
  for (int i = 0; i < is.size(); ++i) ch[is[i] == 'V'].push_back(i + 'a');
  scanf("%d%d", &n, &m);
  L = n << 1;
  g.resize(L << 1);
  for (int i = 0; i < n; ++i) {
    addEdge(i * 2, i * 2 + 1);
    addEdge(Not(i * 2), Not(i * 2 + 1));
  }
  for (int i = 0; i < m; ++i) {
    int p1, p2;
    char t1, t2;
    scanf("%d %c %d %c", &p1, &t1, &p2, &t2);
    --p1;
    --p2;
    p1 = p1 * 2 + (t1 == 'V');
    p2 = p2 * 2 + (t2 == 'V');
    addEdge(Not(p1), p2);
  }
  if (is == string(is.size(), 'V')) {
    for (int i = 0; i < n; ++i) addEdge(i * 2 + 1, i * 2 + 1);
  } else if (is == string(is.size(), 'C')) {
    for (int i = 0; i < n; ++i) addEdge(i * 2, i * 2);
  }
  string s;
  cin >> s;
  vector<vector<int> > G = g;
  vector<int> idx;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] != 'a' + is.size() - 1) idx.push_back(i);
  idx.push_back(n);
  int m, res = -1;
  char nxt;
  for (int mid = 0; mid < idx.size(); ++mid) {
    m = idx[mid];
    for (int i = mid ? idx[mid - 1] : 0; i < m; ++i)
      addEdge(i * 2 + (is[s[i] - 'a'] == 'V'), i * 2 + (is[s[i] - 'a'] == 'V'));
    if (m == n) {
      if (check()) {
        res = m;
      }
      continue;
    }
    char mn = 'z' + 1;
    for (int it = 0; it < 2; ++it) {
      auto ix = upper_bound(ch[it].begin(), ch[it].end(), s[m]);
      if (ix == ch[it].end()) continue;
      char c = *ix;
      int u = m * 2 + (is[c - 'a'] == 'V');
      addEdge(u, u);
      if (check()) mn = min(mn, c);
      g[Not(u)].pop_back();
      g[Not(u)].pop_back();
    }
    if (mn <= 'z') {
      res = m;
      nxt = mn;
    }
  }
  string sol = "-1";
  if (res != -1) {
    sol = s.substr(0, res);
    if (res != n) sol += nxt;
    g = G;
    for (int i = 0; i < sol.size(); ++i)
      addEdge(i * 2 + (is[sol[i] - 'a'] == 'V'),
              i * 2 + (is[sol[i] - 'a'] == 'V'));
    for (int i = res + 1; i < s.size(); ++i) {
      char mn = 'z' + 1;
      for (int it = 0; it < 2; ++it) {
        auto ix = ch[it].begin();
        if (ix == ch[it].end()) continue;
        char c = *ix;
        int u = i * 2 + (is[c - 'a'] == 'V');
        addEdge(u, u);
        if (check()) mn = min(mn, c);
        g[Not(u)].pop_back();
        g[Not(u)].pop_back();
      }
      int u = i * 2 + (is[mn - 'a'] == 'V');
      addEdge(u, u);
      sol += mn;
    }
  }
  cout << sol << endl;
  return 0;
}
