#include <bits/stdc++.h>
using namespace std;
char s[30];
int ty[30];
char ned[202];
int ls;
int len;
int n, m;
bool mark[500];
int rep[500];
vector<int> G[500];
vector<int> tp;
int op;
int getid(int x, char c) { return c == 'V' ? (x << 1) : (x << 1 | 1); }
int find(int st, int Ty) {
  for (int i = st; i < ls; i++)
    if (ty[i] == Ty) return i;
  return ls;
}
bool dfs(int u) {
  if (mark[u]) return 1;
  if (mark[u ^ 1]) return 0;
  int l = u >> 1;
  int Ty = u > (u ^ 1) ? 1 : 0;
  mark[u] = 1;
  tp.push_back(u);
  if (l <= len) {
    if (ty[ned[l] - 'a'] != Ty) return false;
    rep[l] = ned[l] - 'a';
  } else {
    int c = find(l == len + 1 ? (ned[l] - 'a' + 1) : 0, Ty);
    if (c == ls) return false;
    rep[l] = c;
  }
  for (int i = 0; i < G[u].size(); i++)
    if (!dfs(G[u][i])) return false;
  return true;
}
bool check() {
  memset(mark, 0, sizeof(mark));
  for (int i = 1; i <= n; i++) {
    if (mark[i << 1] || mark[i << 1 | 1]) continue;
    int c = ned[i] - 'a';
    if (i <= len) {
      if (!dfs(i << 1 | ty[c])) return false;
    } else {
      int a, b;
      if (i == len + 1) {
        a = find(c + 1, 0);
        b = find(c + 1, 1);
      } else {
        a = find(0, 0);
        b = find(0, 1);
      }
      int fid, fa;
      if (a < b)
        fid = i << 1, fa = a;
      else
        fid = i << 1 | 1, fa = b;
      tp.clear();
      if (!dfs(fid)) {
        for (int j = 0; j < tp.size(); j++) mark[tp[j]] = 0;
        if (a + b - fa == ls || !dfs(fid ^ 1)) return false;
      }
    }
  }
  for (int i = 1; i <= n; i++) putchar(rep[i] + 'a');
  return 1;
}
int main() {
  scanf("%s", s);
  ls = strlen(s);
  for (int i = 0; i < ls; i++) ty[i] = s[i] == 'V' ? 0 : 1;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x;
    char c;
    scanf("%d %c", &x, &c);
    int id1 = getid(x, c);
    scanf("%d %c", &x, &c);
    int id2 = getid(x, c);
    G[id1].push_back(id2);
    G[id2 ^ 1].push_back(id1 ^ 1);
  }
  scanf("%s", ned + 1);
  for (len = n; len >= 0; len--) {
    if (check()) return 0;
  }
  puts("-1");
}
