#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 500;
const long double PI = acos(-1.0);
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
int n, m;
char v[maxn], s[maxn];
vector<int> nex[maxn];
int flag[maxn], ind[4];
map<char, int> ch;
int min1, min2, minn;
void dfs(int x) {
  flag[x] = 1;
  for (int i = 0; i < nex[x].size(); i++)
    if (flag[nex[x][i]] == 0) dfs(nex[x][i]);
  return;
}
bool judge() {
  for (int i = 1; i <= n; i++)
    if ((flag[i] != 0 && flag[n + i] != 0) || (flag[i] != 0 && min1 == 50) ||
        (flag[n + i] != 0 && min2 == 50))
      return true;
  return false;
}
void dfs3(int x) {
  flag[x] = 2;
  for (int i = 0; i < nex[x].size(); i++)
    if (flag[nex[x][i]] == 0) dfs3(nex[x][i]);
  return;
}
void dfs4(int x) {
  flag[x] = 0;
  for (int i = 0; i < nex[x].size(); i++)
    if (flag[nex[x][i]] == 2) dfs4(nex[x][i]);
  return;
}
bool dfs2(int cur, int x) {
  flag[x] = 2;
  for (int i = 0; i < nex[x].size(); i++)
    if (flag[nex[x][i]] == 0) dfs3(nex[x][i]);
  for (int i = cur + 1; i <= n; i++)
    if (flag[i] == 0 && flag[n + i] == 0) {
      if (min1 < min2) {
        if (dfs2(i, i)) return true;
      } else {
        if (dfs2(i, n + i)) return true;
      }
      for (int i = 0; i < nex[x].size(); i++)
        if (flag[nex[x][i]] == 2) dfs4(nex[x][i]);
      flag[x] = 0;
      return false;
    }
  if (judge()) {
    for (int i = 0; i < nex[x].size(); i++)
      if (flag[nex[x][i]] == 2) dfs4(nex[x][i]);
    flag[x] = 0;
    return false;
  }
  return true;
}
int main() {
  while (~scanf("%s", v)) {
    char a = 'V', b = 'C';
    ch[a] = 0;
    ch[b] = 1;
    int l = strlen(v);
    min1 = 50;
    min2 = 50;
    minn = 50;
    for (int i = 0; i < l; i++) {
      if (min1 == 50 && v[i] == 'V') min1 = i;
      if (min2 == 50 && v[i] == 'C') min2 = i;
    }
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 2 * n; i++) nex[i].clear();
    for (int i = 1; i <= m; i++) {
      int u, v;
      char s1[4], s2[4];
      scanf("%d%s%d%s", &u, s1, &v, s2);
      nex[n * ch[s1[0]] + u].push_back(n * ch[s2[0]] + v);
      nex[n * (1 - ch[s2[0]]) + v].push_back(n * (1 - ch[s1[0]]) + u);
    }
    scanf("%s", s);
    memset(flag, 0, sizeof(flag));
    for (int j = 0; j < n; j++) {
      if (v[s[j] - 'a'] == 'V' && flag[j + 1] == 0) {
        flag[j + 1] = 1;
        dfs(j + 1);
      }
      if (v[s[j] - 'a'] == 'C' && flag[n + j + 1] == 0) {
        flag[n + j + 1] = 1;
        dfs(n + j + 1);
      }
    }
    if (!judge()) {
      printf("%s\n", s);
      continue;
    }
    int ff = -1, gg;
    for (int i = n - 1; i >= 0; i--) {
      memset(flag, 0, sizeof(flag));
      for (int j = 0; j < i; j++) {
        if (v[s[j] - 'a'] == 'V' && flag[j + 1] == 0) {
          flag[j + 1] = 1;
          dfs(j + 1);
        }
        if (v[s[j] - 'a'] == 'C' && flag[n + j + 1] == 0) {
          flag[n + j + 1] = 1;
          dfs(n + j + 1);
        }
      }
      if (judge()) continue;
      memset(ind, 0, sizeof(ind));
      for (int j = s[i] - 'a' + 1; j < l; j++) {
        if (ind[ch[v[j]]] == 0) {
          ind[ch[v[j]]] = 1;
          if (dfs2(i + 1, ch[v[j]] * n + i + 1)) {
            ff = i;
            gg = j;
            break;
          }
        }
      }
      if (ff != -1) break;
    }
    if (ff == -1) {
      cout << -1 << endl;
      continue;
    }
    for (int i = ff + 1; i < n; i++)
      if (flag[i + 1] != 0)
        s[i] = 'a' + min1;
      else
        s[i] = 'a' + min2;
    s[ff] = gg + 'a';
    printf("%s\n", s);
  }
  return 0;
}
