#include <bits/stdc++.h>
using namespace std;
const int MAXN = 410;
int l;
int a[30];
int d[MAXN][MAXN];
int ins[MAXN];
char res[210];
string s;
void dfs(int o, int n, int larger) {
  if (o == n) {
    for (int i = 0; i < n; i++) cout << res[i];
    cout << endl;
    exit(0);
  }
  int k = s[o] - 'a';
  int vis[2] = {0, 0};
  for (int i = (larger ? 0 : k); i < l; i++) {
    if (a[i] == 0 && ins[o * 2 + 1]) continue;
    if (a[i] == 1 && ins[o * 2]) continue;
    if (d[o * 2 + a[i]][o * 2 + 1 - a[i]]) continue;
    if (i > k && vis[a[i]]) continue;
    if (i > k) vis[a[i]] = 1;
    for (int j = 0; j < n * 2; j++) ins[j] += d[o * 2 + a[i]][j];
    res[o] = char(i + 'a');
    dfs(o + 1, n, larger | (i > k));
    for (int j = 0; j < n * 2; j++) ins[j] -= d[o * 2 + a[i]][j];
  }
}
int main() {
  cin >> s;
  l = s.length();
  for (int i = 0; i < l; i++) a[i] = s[i] == 'C';
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    char uc, vc;
    cin >> u >> uc >> v >> vc;
    u--;
    v--;
    int su = uc == 'C';
    int sv = vc == 'C';
    d[u * 2 + su][v * 2 + sv] = 1;
    d[v * 2 + 1 - sv][u * 2 + 1 - su] = 1;
  }
  for (int k = 0; k < n * 2; k++)
    for (int i = 0; i < n * 2; i++)
      if (d[i][k])
        for (int j = 0; j < n * 2; j++)
          if (d[k][j]) d[i][j] = 1;
  for (int i = 0; i < n; i++)
    if (d[i * 2][i * 2 + 1] && d[i * 2 + 1][i * 2]) {
      cout << -1 << endl;
      return 0;
    }
  cin >> s;
  int ct[2] = {0, 0};
  for (int i = 0; i < l; i++) ct[a[i]]++;
  if (ct[0] == 0 || ct[1] == 0) {
    int k = ct[1] != 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (d[i * 2 + k][j * 2 + 1 - k]) {
          cout << -1 << endl;
          return 0;
        }
    cout << s << endl;
    return 0;
  }
  dfs(0, n, 0);
  cout << -1 << endl;
  return 0;
}
