#include <bits/stdc++.h>
using namespace std;
string a, str, ans;
int n, m;
int G[205 * 2][205 * 2];
bool check(int x, int y) {
  bool f1 = (a[ans[x] - 'a'] == 'C'), f2 = (a[ans[y] - 'a'] == 'C');
  int ta = 2 * x + 2, tb = 2 * y + 2;
  return !G[ta - f1][tb - (!f2)] && !G[tb - f2][ta - (!f1)];
}
bool DFS(int now, bool p) {
  if (now == n) {
    cout << ans << endl;
    return true;
  }
  int lw = (p == true) ? 0 : str[now] - 'a';
  for (int i = lw; i < a.length(); i++) {
    ans[now] = i + 'a';
    bool f = true;
    for (int j = 0; j <= now; j++) {
      if (check(j, now) == false) {
        f = false;
        break;
      }
    }
    if (f == false) continue;
    if (DFS(now + 1, p || (ans[now] > str[now]))) return true;
  }
  return false;
}
int main() {
  cin >> a >> n >> m;
  for (int i = 1, p1, p2; i <= m; i++) {
    char t1, t2;
    scanf("%d %c %d %c", &p1, &t1, &p2, &t2);
    bool f1 = (t1 == 'C'), f2 = (t2 == 'C');
    int x = 2 * p1, y = 2 * p2;
    G[x - f1][y - f2] = G[y - (!f2)][x - (!f1)] = 1;
  }
  int c[2] = {0};
  for (int i = 0; i < a.length(); i++) c[a[i] == 'C'] = 1;
  if (c[1] == 0 || c[0] == 0) {
    for (int i = 1; i <= n; i++) G[2 * i - c[0]][2 * i - (!c[0])] = 1;
  }
  cin >> str;
  for (int t = 1; t <= 2 * n; t++) {
    for (int i = 1; i <= 2 * n; i++) {
      for (int j = 1; j <= 2 * n; j++)
        if (G[i][t] && G[t][j]) G[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    int x = 2 * i, y = 2 * i - 1;
    if (G[x][y] && G[y][x]) {
      puts("-1");
      return 0;
    }
    ans += ' ';
  }
  if (DFS(0, 0) == false) puts("-1");
  return 0;
}
