#include <bits/stdc++.h>
using namespace std;
const int N = 405;
bool mat[N][N];
int n, m, l;
char x[N];
char type[30];
char nxto[128];
char nxtz[128];
bool get(char c) { return (type[c - 'a'] == 'C'); }
int getId(int idx, char c) { return 2 * idx + (c == 'C'); }
int state[N];
vector<int> vec;
bool dfs(int cur, int p) {
  if (state[cur] != -1) return (state[cur] == p);
  vec.push_back(cur);
  state[cur] = p;
  if (p == 1) {
    for (int i = 0; i < 2 * n; ++i)
      if (mat[cur][i] && state[i] == -1) state[i] = p, vec.push_back(i);
  } else {
    for (int i = 0; i < 2 * n; ++i)
      if (mat[i][cur] && state[i] == -1) state[i] = p, vec.push_back(i);
  }
  dfs(cur ^ 1, p ^ 1);
  return 1;
}
char result[N];
bool solve(int idx, bool isg);
bool check(int idx, char c, int isg) {
  if (c == -1) return 0;
  vector<int> v;
  bool res = dfs(2 * idx, !get(c));
  v = vec;
  vec.clear();
  if (!res) return 0;
  if (solve(idx + 1, isg || c > x[idx])) return result[idx] = c, 1;
  for (int i = 0; i < v.size(); ++i) state[v[i]] = -1;
  return 0;
}
bool solve(int idx, bool isg) {
  if (idx == n) return 1;
  char a, b;
  if (isg) {
    a = nxtz['a'];
    b = nxto['a'];
  } else {
    if (check(idx, x[idx], isg)) return 1;
    a = nxtz[x[idx] + 1];
    b = nxto[x[idx] + 1];
  }
  if (a > b) swap(a, b);
  if (check(idx, a, isg)) return 1;
  if (check(idx, b, isg)) return 1;
  return 0;
}
int main() {
  scanf(" %s", type);
  l = strlen(type);
  nxto['a' + l] = nxtz['a' + l] = -1;
  for (char c = 'a' + l - 1; c >= 'a'; c--) {
    nxto[c] = nxto[c + 1];
    nxtz[c] = nxtz[c + 1];
    if (get(c))
      nxto[c] = c;
    else
      nxtz[c] = c;
  }
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int p1, p2;
    char t1, t2;
    scanf("%d %c %d %c", &p1, &t1, &p2, &t2);
    p1--, p2--;
    mat[getId(p1, t1)][getId(p2, t2)] = 1;
    mat[getId(p2, t2) ^ 1][getId(p1, t1) ^ 1] = 1;
  }
  scanf(" %s", x);
  for (int i = 0; i < 2 * n; ++i)
    for (int j = 0; j < 2 * n; ++j)
      for (int k = 0; k < 2 * n; ++k) mat[j][k] |= (mat[j][i] && mat[i][k]);
  for (int i = 0; i < n; ++i)
    if (mat[2 * i][2 * i + 1] && mat[2 * i + 1][2 * i]) return puts("-1");
  memset(state, -1, sizeof state);
  for (int i = 0; i < n; ++i) {
    if (mat[2 * i][2 * i + 1]) dfs(2 * i, 0);
    if (mat[2 * i + 1][2 * i]) dfs(2 * i + 1, 0);
  }
  vec.clear();
  if (!solve(0, 0)) return puts("-1");
  printf("%s\n", result);
}
