#include <bits/stdc++.h>
using namespace std;
char rule[30];
char str[1000], str2[1000];
int S[1000];
vector<int> g[1000];
vector<char> V, C;
int mark[1000];
bool Vhigh;
int cnt;
int n;
void init() {
  V.clear();
  C.clear();
  for (int i = 0; i < 1000; i++) {
    g[i].clear();
  }
}
bool dfs(int x) {
  if (mark[x ^ 1]) return false;
  if (mark[x]) return true;
  mark[x] = 1;
  S[cnt++] = x;
  for (int _i = 0; _i < g[x].size(); _i++) {
    int i = g[x][_i];
    if (!dfs(i)) return false;
  }
  return true;
}
char MM;
bool solve(int F) {
  memset(mark, 0, sizeof(mark));
  for (int i = 0; i < n; i++) {
    cnt = 0;
    if (i <= F) {
      if (str[i] == 'V') {
        if (!dfs(i * 2)) return false;
      } else {
        if (!dfs(i * 2 + 1)) return false;
      }
    } else if (i == F + 1) {
      if (str2[i] == MM) return false;
      if (rule[str2[i] - 'a' + 1] == 'V') {
        if (!dfs(i * 2)) {
          if (C.size() != 0 &&
              upper_bound(C.begin(), C.end(), str2[i]) != C.end()) {
            while (cnt > 0) mark[S[--cnt]] = 0;
            if (!dfs(i * 2 + 1)) return false;
          } else {
            return false;
          }
        }
      }
      if (rule[str2[i] - 'a' + 1] == 'C') {
        if (!dfs(i * 2 + 1)) {
          if (V.size() != 0 &&
              upper_bound(V.begin(), V.end(), str2[i]) != V.end()) {
            while (cnt > 0) mark[S[--cnt]] = 0;
            if (!dfs(i * 2)) return false;
          } else {
            return false;
          }
        }
      }
    } else if (!mark[i * 2] && !mark[i * 2 + 1]) {
      if (Vhigh) {
        if (!dfs(i * 2)) {
          while (cnt > 0) mark[S[--cnt]] = 0;
          if (C.size() == 0) return false;
          if (!dfs(i * 2 + 1)) return false;
        }
      } else {
        if (!dfs(i * 2 + 1)) {
          while (cnt > 0) mark[S[--cnt]] = 0;
          if (V.size() == 0) return false;
          if (!dfs(i * 2)) return false;
        }
      }
    }
  }
  return true;
}
bool output(int F) {
  vector<char> ans;
  for (int i = 0; i <= F; i++) {
    ans.push_back(str2[i]);
  }
  if (F + 1 < n) {
    int i = F + 1;
    if (mark[i * 2]) {
      if (V.size() == 0) return false;
      char c = *upper_bound(V.begin(), V.end(), str2[i]);
      ans.push_back(c);
    } else {
      if (C.size() == 0) return false;
      char c = *upper_bound(C.begin(), C.end(), str2[i]);
      ans.push_back(c);
    }
  }
  for (int i = F + 2; i < n; i++) {
    if (mark[i * 2]) {
      if (V.size() == 0) return false;
      ans.push_back(V[0]);
    } else {
      if (C.size() == 0) return false;
      ans.push_back(C[0]);
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%c", ans[i]);
  }
  puts("");
  return true;
}
int main() {
  int m;
  int p1, p2;
  int t1, t2;
  char cmd1[3], cmd2[3];
  while (scanf("%s", rule) != EOF) {
    init();
    MM = 'a' + strlen(rule) - 1;
    for (int i = 0; i < strlen(rule); i++) {
      if (rule[i] == 'V')
        V.push_back(i + 'a');
      else
        C.push_back(i + 'a');
    }
    Vhigh = true;
    if (C.size() == 0) {
      Vhigh = true;
    } else if (V.size() == 0) {
      Vhigh = false;
    } else if (V[0] < C[0]) {
      Vhigh = true;
    } else
      Vhigh = false;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
      scanf("%d %s %d %s", &p1, cmd1, &p2, cmd2);
      p1--;
      p2--;
      t1 = cmd1[0] == 'V' ? 0 : 1;
      t2 = cmd2[0] == 'V' ? 0 : 1;
      g[2 * p1 + t1].push_back(2 * p2 + t2);
      g[(2 * p2 + t2) ^ 1].push_back((2 * p1 + t1) ^ 1);
    }
    scanf("%s", str2);
    memset(mark, 0, sizeof(mark));
    for (int _i = 0; _i < n; _i++) {
      int i = str2[_i] - 'a';
      str[_i] = rule[i];
    }
    bool flag = 0;
    for (int i = n - 1; i >= -1; i--) {
      if (solve(i)) {
        flag = 1;
        if (!output(i)) flag = 0;
        break;
      }
    }
    if (!flag) {
      puts("-1");
    }
  }
  return 0;
}
