#include <bits/stdc++.h>
using namespace std;
namespace TwoSat {
const int nodes = 510;
int g[nodes][nodes];
vector<int> ed[nodes];
int n, cnt, top, ind;
int low[nodes], st[nodes], disc[nodes], comp[nodes], inst[nodes];
vector<int> result;
void init(int ct) {
  n = ct;
  cnt = top = ind = 0;
  memset(g, 0, sizeof(g));
  for (int i = 0; i <= n; i++) ed[i].clear();
}
void add(int u, int v) {
  if (g[u][v]) return;
  ed[u].push_back(v);
  g[u][v] = 1;
}
void add_disjunction(int u, int v) {
  add(u ^ 1, v);
  add(v ^ 1, u);
}
void tarjan(int u) {
  disc[u] = low[u] = ++ind;
  inst[u] = 1;
  st[++top] = u;
  for (int i = 0; i < (int)ed[u].size(); i++) {
    int v = ed[u][i];
    if (!disc[v])
      tarjan(v), low[u] = min(low[v], low[u]);
    else if (inst[v])
      low[u] = min(low[u], disc[v]);
  }
  if (disc[u] == low[u]) {
    ++cnt;
    while (true) {
      comp[st[top]] = cnt;
      inst[st[top]] = 0;
      if (st[top--] == u) break;
    }
  }
}
bool solve() {
  memset(disc, 0, sizeof(disc));
  for (int i = 0; i < n; i++) {
    if (!disc[i]) tarjan(i);
  }
  for (int i = 0; i < n; i += 2) {
    if (comp[i] == comp[i ^ 1])
      return 0;
    else if (comp[i] > comp[i ^ 1])
      result.push_back(i / 2);
  }
  return 1;
}
}  // namespace TwoSat
string T, s, ans;
const int N = 2e5;
pair<int, int> check[N];
int n, m, len;
bool ac, av;
bool solve(int l) {
  TwoSat::init(n * 2);
  for (int i = 0; i < m; i++) {
    int u = check[i].first;
    int v = check[i].second;
    TwoSat::add_disjunction(u ^ 1, v);
  }
  for (int i = 0; i < l; i++) {
    if (T[ans[i] - 'a'] == 'V')
      TwoSat::add(i * 2, i * 2 + 1);
    else
      TwoSat::add(i * 2 + 1, i * 2);
  }
  for (int i = 0; i < n; i++) {
    if (ac) TwoSat::add(i * 2 + 1, i * 2);
    if (av) TwoSat::add(i * 2, i * 2 + 1);
  }
  bool flg = TwoSat::solve();
  return flg;
}
void dfs(int d, int flag) {
  if (d == n) {
    cout << ans << endl;
    exit(0);
  } else {
    int v = 0, c = 0;
    for (int i = (flag ? 0 : s[d] - 'a'); i < len; i++) {
      ans[d] = i + 'a';
      if (T[i] == 'V') {
        if (v >= 2) continue;
        v++;
      }
      if (T[i] == 'C') {
        if (c >= 2) continue;
        c++;
      }
      if (solve(d + 1)) {
        dfs(d + 1, flag | (i != (s[d] - 'a')));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ac = true;
  av = true;
  cin >> T;
  len = (int)T.length();
  for (int i = 0; i < len; i++) {
    ac = ac & (T[i] == 'C');
    av = av & (T[i] == 'V');
  }
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int p1, p2;
    char ch1, ch2;
    cin >> p1 >> ch1 >> p2 >> ch2;
    p1--, p2--;
    int u = p1 * 2 + (ch1 == 'V');
    int v = p2 * 2 + (ch2 == 'V');
    check[i] = make_pair(u, v);
  }
  cin >> s;
  ans = s;
  dfs(0, 0);
  cout << -1 << endl;
  return 0;
}
