#include <bits/stdc++.h>
using namespace std;
const int MAXN = 600;
int n, m, l;
char word[MAXN];
int cho[MAXN];
char str[MAXN], cur, endletter;
bool edge[MAXN][MAXN], can[22];
int kind(char c) { return c == 'C'; }
bool bad(int i, int j) { return edge[i][j ^ 1] || edge[j][i ^ 1]; }
bool check(int at, char st) {
  for (int k = 0; k < 2; k++) {
    can[k] = true;
    cho[at] = at * 2 + k;
    for (int i = 0; i <= at; i++)
      if (bad(cho[at], cho[i])) {
        can[k] = false;
        break;
      }
  }
  if (!can[0] && !can[1]) return false;
  for (word[at] = st; word[at] < endletter && !can[kind(str[word[at] - 'a'])];
       word[at]++)
    ;
  if (word[at] >= endletter) return false;
  cho[at] = at * 2 + kind(str[word[at] - 'a']);
  return true;
}
int checksame() {
  int at;
  for (int i = 0; i < n; i++) cho[i] = i * 2 + kind(str[word[i] - 'a']);
  for (at = 0; at < n; at++) {
    int i;
    for (i = 0; i <= at; i++)
      if (bad(cho[at], cho[i])) break;
    if (i <= at) break;
  }
  return at;
}
int main() {
  scanf("%s", str);
  l = strlen(str);
  endletter = 'a' + strlen(str);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int p1, p2;
    char t1[20], t2[20];
    scanf("%d%s", &p1, t1);
    int k1 = kind(t1[0]);
    scanf("%d%s", &p2, t2);
    int k2 = kind(t2[0]);
    p1--, p2--;
    edge[p1 * 2 + k1][p2 * 2 + k2] = true;
    edge[p2 * 2 + 1 - k2][p1 * 2 + 1 - k1] = true;
  }
  scanf("%s", word);
  for (int k = 0; k < 2 * n; k++)
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++) edge[i][j] |= (edge[i][k] && edge[k][j]);
  int at = checksame();
  if (at >= n) {
    printf("%s\n", word);
    return 0;
  }
  for (; at >= 0; at--) {
    if (!check(at, word[at] + 1)) continue;
    for (int i = at + 1; i < n; i++)
      if (!check(i, 'a')) {
        printf("-1\n");
        return 0;
      }
    printf("%s\n", word);
    return 0;
  }
  if (at < 0) printf("-1\n");
  return 0;
}
