#include <bits/stdc++.h>
using namespace std;
int N, M, L, T, V[2], A[405], B[405], G[405], Ans[405];
char s[405];
bitset<405> F[405];
bool FANGAN(int i, bitset<405> Now) {
  for (int j = i; j <= N; j++) {
    if (!((F[j << 1] & Now).count()) && G[j << 1]) continue;
    if (!((F[j << 1 | 1] & Now).count()) && G[j << 1 | 1]) continue;
    return 0;
  }
  return 1;
}
void Find(int d, bitset<405> Now) {
  for (int i = d; i <= N; i++) {
    int k = L;
    for (; k; k--) {
      if ((F[i << 1 | A[k]] & Now).count() || !G[i << 1 | A[k]]) continue;
      bitset<405> tmp = Now;
      for (int j = 2; j <= T; j++)
        if (F[i << 1 | A[k]][j]) Now[j ^ 1] = 1;
      if (FANGAN(i + 1, Now)) break;
      Now = tmp;
    }
    if (!k) {
      for (int j = d; j <= N; j++) B[j] = 0;
      return;
    }
    B[i] = k;
  }
}
int main() {
  scanf("%s", s + 1);
  L = strlen(s + 1);
  for (int i = 1; i <= L; i++) A[i] = (s[i] == 'V'), V[A[i]] = 1;
  scanf("%d%d", &N, &M);
  for (int i = 1, u, v; i <= M; i++) {
    scanf("%d%s", &u, s);
    u = u * 2 + (s[0] == 'V');
    scanf("%d%s", &v, s);
    v = v * 2 + (s[0] == 'V');
    F[u][v] = F[v ^ 1][u ^ 1] = 1;
  }
  T = 2 * N + 1;
  for (int i = 2; i <= T; i++) F[i][i] = 1;
  for (int k = 2; k <= T; k++)
    for (int i = 2; i <= T; i++)
      if (F[i][k]) F[i] |= F[k];
  for (int i = 1; i <= N; i++)
    if (F[i << 1][i << 1 | 1] && G[0] || F[i << 1 | 1][i << 1] && G[1])
      return puts("-1"), 0;
  scanf("%s", s + 1);
  for (int i = 1; i <= N; i++) s[i] -= 'a' - 1;
  for (int i = 2; i <= T; i++) G[i] = 1;
  for (int i = 2; i <= T; i++)
    for (int j = 2; j <= T; j++)
      if (F[i][j]) G[i] &= V[j & 1];
  int flag = 0;
  bitset<405> Now;
  Now.reset();
  for (int i = 1; i <= N; i++) {
    int k = (flag ? 1 : s[i]);
    for (; k <= L; k++) {
      flag |= (k > s[i]);
      if ((F[i << 1 | A[k]] & Now).count() || !G[i << 1 | A[k]]) continue;
      bitset<405> tmp = Now;
      for (int j = 2; j <= T; j++)
        if (F[i << 1 | A[k]][j]) Now[j ^ 1] = 1;
      int OK = 1;
      if (flag)
        OK = FANGAN(i + 1, Now);
      else {
        Find(i + 1, Now);
        int t = 0;
        for (int j = i + 1; j <= N; j++) {
          if (s[j] > B[j]) {
            t = 1;
            break;
          }
          if (s[j] < B[j]) {
            t = -1;
            break;
          }
        }
        if (t == 1) OK = 0;
      }
      if (OK) break;
      Now = tmp;
    }
    if (k > L) return puts("-1"), 0;
    Ans[i] = k;
  }
  for (int i = 1; i <= N; i++) printf("%c", 'a' + Ans[i] - 1);
  puts("");
}
