#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210;
const int MASKSZ = 2 * MAXN;
struct rib {
  int pos;
  int t;
  rib(int pos = 0, int t = 0) : pos(pos), t(t) {}
};
char buf[MAXN], buf1[100], buf2[100];
vector<rib> g[2][MAXN];
bitset<MASKSZ> closure[2][MAXN];
bool used[2][MAXN];
void dfs(int t, int v) {
  if (used[t][v]) return;
  closure[t][v].set(2 * v + t);
  used[t][v] = true;
  for (const rib &r : g[t][v]) {
    dfs(r.t, r.pos);
    closure[t][v] |= closure[r.t][r.pos];
  }
}
inline bool check(const bitset<MASKSZ> &mask, int len) {
  for (int i = 1; i <= len; ++i)
    if (mask[2 * i] && mask[2 * i + 1]) return false;
  return true;
}
void print_bs(const bitset<MASKSZ> &mask, int len) {
  for (int i = 1; i <= len; ++i) cout << mask[2 * i] << mask[2 * i + 1];
  cout << endl;
}
void generate() {
  int l = 26;
  for (int i = 0; i < 26; ++i) putchar(rand() % 2 ? 'C' : 'V');
  puts("");
  int n = 200;
  int m = 4 * n * (n - 1);
  printf("%d %d\n", n, m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (i != j)
        for (int t1 = 0; t1 < 2; ++t1)
          for (int t2 = 0; t2 < 2; ++t2)
            printf("%d %c %d %c\n", i, t1 ? 'C' : 'V', j, t2 ? 'C' : 'V');
  for (int i = 0; i < n; ++i) putchar('a' + rand() % l);
  puts("");
  exit(0);
}
int main() {
  scanf("%s", buf);
  vector<int> alph(300, -1);
  int l = strlen(buf);
  for (int i = 0; i < l; ++i) alph['a' + i] = buf[i] == 'C';
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int pos1, pos2;
    scanf("%d%s%d%s", &pos1, buf1, &pos2, buf2);
    int t1 = *buf1 == 'C', t2 = *buf2 == 'C';
    g[t1][pos1].push_back(rib(pos2, t2));
    g[!t2][pos2].push_back(rib(pos1, !t1));
  }
  buf[0] = '.';
  scanf("%s", buf + 1);
  string s(buf);
  for (int t = 0; t < 2; ++t)
    for (int pos = 1; pos <= n; ++pos) dfs(t, pos);
  pair<char, int> repl[2];
  for (int i = 0; i < 2; ++i) {
    repl[i].second = i;
    repl[i].first = 'a';
    while (repl[i].first < 'a' + l && alph[repl[i].first] != i) ++repl[i].first;
  }
  sort(repl, end(repl));
  string res;
  for (int pref = n; pref >= 0; --pref) {
    res = s;
    bitset<MASKSZ> mask;
    bitset<MASKSZ> next;
    for (int i = 1; i <= pref; ++i) mask |= closure[alph[res[i]]][i];
    if (!check(mask, n)) continue;
    if (pref < n) {
      ++res[pref + 1];
      for (; res[pref + 1] < 'a' + l; ++res[pref + 1]) {
        next = mask;
        next |= closure[alph[res[pref + 1]]][pref + 1];
        if (check(next, n)) {
          mask = next;
          break;
        }
      }
      if (res[pref + 1] == 'a' + l) continue;
    }
    bool ok = true;
    for (int i = pref + 2; i <= n; ++i) {
      bool ok_r = false;
      for (int r = 0; r < 2; ++r)
        if (repl[r].first < 'a' + l) {
          next = mask;
          next |= closure[repl[r].second][i];
          if (check(next, n)) {
            mask = next;
            res[i] = repl[r].first;
            ok_r = true;
            break;
          }
        }
      if (!ok_r) {
        ok = false;
        break;
      }
    }
    if (ok) {
      puts(res.c_str() + 1);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
