#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<int, int>;
vector<pii> adj[222][2];
vector<pii> rev[222][2];
int flag[222];
int can[110];
char s[222];
int ok[111];
vector<int> res;
int dfs(int u) {
  res.push_back(u);
  if (!ok[flag[u]]) return 0;
  for (auto p : adj[u][flag[u]]) {
    int u = p.first, st = p.second;
    if (flag[u] == (st ^ 1)) return 0;
    if (flag[u] == -1) {
      flag[u] = st;
      if (!dfs(u)) return 0;
    }
  }
  for (auto p : rev[u][flag[u] ^ 1]) {
    int u = p.first, st = p.second;
    if (flag[u] == st) return 0;
    if (flag[u] == -1) {
      flag[u] = (st ^ 1);
      if (!dfs(u)) return 0;
    }
  }
  return 1;
}
int calc(int u) {
  res.clear();
  if (!dfs(u)) {
    for (int x : res) flag[x] = -1;
    return 0;
  }
  return 1;
}
int solve(int u, int n) {
  memset(flag, -1, sizeof flag);
  for (int i = 0; i < u; i++) {
    if (flag[i] != -1 and flag[i] != can[s[i] - 'a']) return 0;
    if (flag[i] == can[s[i] - 'a']) continue;
    flag[i] = can[s[i] - 'a'];
    if (!calc(i)) return 0;
  }
  if (u == n) {
    for (int i = 0; i < n; i++) printf("%c", s[i]);
    exit(0);
    return 1;
  }
  if (flag[u] == -1) {
    for (int j = s[u] - 'a' + 1; j <= 25; j++)
      if (can[j] != -1) {
        flag[u] = can[j];
        if (calc(u)) break;
        for (int k = j + 1; k <= 25; k++)
          if (can[k] != -1 and can[k] != can[j]) {
            flag[u] = can[k];
            if (!calc(u)) return 0;
            break;
          }
        break;
      }
    if (flag[u] == -1) return 0;
  } else {
    int cnt = 0;
    for (int j = s[u] - 'a' + 1; j <= 25; j++)
      if (can[j] == flag[u]) cnt++;
    if (cnt == 0) return 0;
  }
  for (int i = u + 1; i < n; i++)
    if (flag[i] == -1) {
      for (int j = 0; j < 2; j++) {
        for (int k = 0; k <= 25; k++)
          if (can[k] == (can[0] ^ j)) {
            flag[i] = (can[0] ^ j);
            calc(i);
            break;
          }
        if (flag[i] != -1) break;
      }
      if (flag[i] == -1) return 0;
    }
  for (int i = 0; i < u; i++) printf("%c", s[i]);
  for (int i = s[u] - 'a' + 1; i <= 25; i++)
    if (flag[u] == can[i]) {
      printf("%c", 'a' + i);
      break;
    }
  for (int i = u + 1; i < n; i++) {
    for (int j = 0; j <= 25; j++)
      if (can[j] == flag[i]) {
        printf("%c", 'a' + j);
        break;
      }
  }
  exit(0);
}
int main() {
  memset(can, -1, sizeof can);
  cin >> s;
  int l = strlen(s);
  for (int i = 0; i < l; i++) {
    if (s[i] == 'V')
      can[i] = 1;
    else
      can[i] = 0;
    ok[can[i]] = 1;
  }
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, st1, st2;
    char s1, s2;
    scanf("%d %c %d %c", &u, &s1, &v, &s2);
    u--;
    v--;
    if (s1 == 'V')
      st1 = 1;
    else
      st1 = 0;
    if (s2 == 'V')
      st2 = 1;
    else
      st2 = 0;
    adj[u][st1].push_back(pii(v, st2));
    rev[v][st2].push_back(pii(u, st1));
  }
  scanf("%s", s);
  for (int i = n; i >= 0; i--) {
    solve(i, n);
  }
  puts("-1");
  return 0;
}
