#include <bits/stdc++.h>
using namespace std;
const int M = 505;
int n, m, len;
bool edge[M][M];
char VC[M], sd[M];
char now[M];
int t(char x) { return x == 'C'; }
void Floyd() {
  for (int k = 0; k < n * 2; ++k) {
    for (int i = 0; i < n * 2; ++i) {
      for (int j = 0; j < n * 2; ++j) {
        edge[i][j] |= edge[i][k] & edge[k][j];
      }
    }
  }
}
bool ok(int x, int y) {
  int i = 2 * x + t(VC[now[x] - 'a']), j = 2 * y + t(VC[now[y] - 'a']);
  return !edge[i][j ^ 1] && !edge[j][i ^ 1];
}
void dfs(int x, bool gr) {
  if (x == n) {
    cout << now << endl;
    exit(0);
  }
  bool mark[4] = {false};
  for (char i = gr ? 'a' : sd[x]; i < len + 'a'; ++i) {
    if (mark[0] && mark[1] && mark[2] && mark[3]) break;
    bool big = i > sd[x] || gr;
    if (mark[t(VC[i - 'a']) + big * 2]) continue;
    now[x] = i;
    mark[t(VC[i - 'a']) + big * 2] = true;
    bool chk = true;
    for (int j = 0; j <= x; ++j) {
      if (!ok(j, x)) {
        chk = false;
        break;
      }
    }
    if (chk) dfs(x + 1, gr || now[x] > sd[x]);
  }
}
int main() {
  scanf("%s", VC);
  len = strlen(VC);
  scanf("%d%d", &n, &m);
  bool chk[2] = {false};
  for (int i = 0; i < len; ++i) chk[t(VC[i])] = true;
  if (!chk[0] || !chk[1]) {
    for (int i = 0; i < n; ++i) {
      edge[2 * i + chk[0]][2 * i + chk[0] ^ 1] = 1;
    }
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    char a, b;
    scanf("%d %c %d %c", &x, &a, &y, &b);
    x = 2 * (x - 1) + t(a);
    y = 2 * (y - 1) + t(b);
    edge[x][y] = edge[y ^ 1][x ^ 1] = 1;
  }
  Floyd();
  scanf("%s", sd);
  for (int i = 0; i < 2 * n; ++i) {
    if (edge[i][i ^ 1] && edge[i ^ 1][i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  dfs(0, 0);
  puts("-1");
  return 0;
}
