#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
bool rela[500 + 7][500 + 7];
int n, dp[500 + 7][2], aln;
char alp[50], ans[500 + 7], inp_str[500 + 7];
int not_a(int a) {
  if (a > n) return a - n;
  return a + n;
}
bool check(int a, int b) {
  if (alp[ans[a] - 'a' + 1] == 'C') a += n;
  if (alp[ans[b] - 'a' + 1] == 'C') b += n;
  return !(!rela[a][not_a(b)] && !rela[b][not_a(a)]);
}
int rec(int pos, int st) {
  if (pos > n) return 1;
  int &ret = dp[pos][st];
  if (ret != -1) return ret;
  ret = 0;
  bool ok = 0;
  for (int i = st ? 0 : inp_str[pos] - 'a'; i < aln; i++) {
    ans[pos] = 'a' + i;
    for (int j = 1; j <= pos; j++) {
      ok = check(j, pos);
      if (ok) break;
    }
    if (ok) continue;
    ret = rec(pos + 1, st | (ans[pos] > inp_str[pos]));
    if (ret) return ret;
  }
  return ret = 0;
}
int main() {
  scanf("%s", alp + 1);
  aln = strlen(alp + 1);
  scanf("%d", &n);
  int m, u, v;
  char str1[5], str2[5];
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &u);
    scanf("%s", str1);
    scanf("%d", &v);
    scanf("%s", str2);
    if (str1[0] == 'C') u += n;
    if (str2[0] == 'C') v += n;
    rela[u][v] = 1;
    rela[not_a(v)][not_a(u)] = 1;
  }
  for (int k = 1; k <= n + n; k++) {
    for (int i = 1; i <= n + n; i++) {
      for (int j = 1; j <= n + n; j++) rela[i][j] |= (rela[i][k] & rela[k][j]);
    }
  }
  scanf("%s", inp_str + 1);
  memset(dp, -1, sizeof(dp));
  if (rec(1, 0)) {
    for (int i = 1; i <= n; i++) printf("%c", ans[i]);
    printf("\n");
  } else
    printf("-1\n");
  return 0;
}
