#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
char ch[4000010];
inline string get() {
  scanf("%s", ch);
  return string(ch);
}
inline void read(int *a, int n) {
  for (int i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
template <class blank, class blank2>
inline void smin(blank &a, blank2 b) {
  a = a <= b ? a : b;
}
template <class blank, class blank2>
inline void smax(blank &a, blank2 b) {
  a = a >= b ? a : b;
}
const int maxn = 500 + 10;
const int maxm = 4e6 + 10;
const int maxlg = 20;
const int base = 29;
const int mod = 1e9 + 7;
const long long inf = 2e18 + 10;
const double eps = 1e-9;
string t, word;
int l, tp[50], n, m;
bool mark[maxn];
vector<int> g[maxn], tpl, rev[maxn];
inline void dfs(int node) {
  mark[node] = true;
  for (auto u : g[node])
    if (!mark[u]) dfs(u);
  tpl.push_back(node);
}
int cmp, COMP[maxn];
inline void make_reverse() {
  for (int i = 0; i <= 405; i++) rev[i].clear();
  for (int i = 0; i <= 405; i++)
    for (auto u : g[i]) rev[u].push_back(i);
}
inline void dfs2(int node) {
  mark[node] = true;
  COMP[node] = cmp;
  for (auto u : rev[node])
    if (!mark[u]) dfs2(u);
}
inline bool can(int CONST, int lst) {
  int pre = word[CONST] - 'a';
  word[CONST] = char('a' + lst);
  vector<int> rem;
  for (int i = 0; i <= CONST; i++) {
    g[2 * i + (tp[word[i] - 'a'] ^ 1)].push_back(2 * i + tp[word[i] - 'a']);
    rem.push_back(2 * i + (tp[word[i] - 'a'] ^ 1));
  }
  word[CONST] = char('a' + pre);
  memset(mark, 0, sizeof mark);
  tpl.clear();
  for (int i = 0; i <= 450; i++)
    if (!mark[i]) dfs(i);
  reverse(tpl.begin(), tpl.end());
  make_reverse();
  cmp = 1;
  memset(mark, 0, sizeof mark);
  for (auto v : tpl)
    if (!mark[v]) dfs2(v), cmp++;
  reverse(rem.begin(), rem.end());
  for (auto v : rem) g[v].pop_back();
  for (int i = 0; i <= 450; i++)
    if (COMP[i] == COMP[i ^ 1]) return false;
  return true;
}
int32_t main() {
  t = get();
  l = (int)t.size();
  bool fl = true;
  vector<int> vc[2];
  for (int i = 0; i < l; i++) {
    fl &= (i == 0 || t[i] == t[i - 1]), tp[i] = t[i] == 'V';
    vc[t[i] == 'V'].push_back(i);
  }
  n = in(), m = in();
  for (int i = 0; i < m; i++) {
    int pos1, pos2;
    char ch1 = 0, ch2 = 0;
    pos1 = in() - 1;
    do {
      ch1 = getchar();
    } while (ch1 != 'V' && ch1 != 'C');
    pos2 = in() - 1;
    do {
      ch2 = getchar();
    } while (ch2 != 'V' && ch2 != 'C');
    g[2 * pos2 + (ch2 == 'C')].push_back(2 * pos1 + (ch1 == 'C'));
    g[2 * pos1 + (ch1 == 'V')].push_back(2 * pos2 + (ch2 == 'V'));
  }
  word = get();
  if (fl)
    for (int i = 0; i < n; i++)
      g[2 * i + (tp[word[i] - 'a'] ^ 1)].push_back(2 * i + tp[word[i] - 'a']);
  if (can(n - 1, word[n - 1] - 'a')) out(word);
  fl = false;
  int id = 0;
  for (int i = n - 1; i >= 0; i--) {
    int nxt0, nxt1;
    nxt0 = (int)(upper_bound(vc[0].begin(), vc[0].end(), word[i] - 'a') -
                 vc[0].begin());
    nxt1 = (int)(upper_bound(vc[1].begin(), vc[1].end(), word[i] - 'a') -
                 vc[1].begin());
    int mini = 50;
    if (nxt0 < vc[0].size() && can(i, vc[0][nxt0])) mini = vc[0][nxt0];
    if (nxt1 < vc[1].size() && can(i, vc[1][nxt1])) smin(mini, vc[1][nxt1]);
    if (mini == 50) continue;
    fl = true;
    word[i] = char(mini + 'a');
    id = i;
    i = 0;
    break;
  }
  if (!fl) out(-1);
  for (int i = id + 1; i < n; i++) {
    int nxt0 = 0, nxt1 = 0;
    int mini = 50;
    if (nxt0 < vc[0].size() && can(i, vc[0][nxt0])) mini = vc[0][nxt0];
    if (nxt1 < vc[1].size() && can(i, vc[1][nxt1])) smin(mini, vc[1][nxt1]);
    assert(mini - 50);
    word[i] = char(mini + 'a');
  }
  cout << word << "\n";
}
