#include <bits/stdc++.h>
using namespace std;
vector<int> G[405], gg[405];
int n, m;
int a[2][30], g[405][405];
char s[405];
int vis[405], gs[405], bid[405];
inline void dfs(int u, int o) {
  if (bid[u]) {
    bid[o] = 1;
    return;
  }
  if (gs[u >> 1]) {
    bid[o] = 1;
    return;
  }
  gg[o].push_back(u);
  vis[u] = 1;
  gs[u >> 1] = 1;
  int i, sz = G[u].size();
  for (i = 0; i < sz; ++i) {
    if (vis[G[u][i]]) continue;
    dfs(G[u][i], o);
    if (bid[o]) return;
  }
}
int ans[405], M;
inline int geta(int fl, int x) {
  return *lower_bound(a[fl] + 1, a[fl] + 1 + a[fl][0], x);
}
inline void solve(int i, int o) {
  if (i > n) {
    for (i = 1; i <= n; ++i) putchar('a' + ans[i] - 1);
    exit(0);
  }
  int fl;
  if (!o) {
    if (vis[i]) {
      ans[i] = a[vis[i] - 1][1];
      return solve(i + 1, 0);
    }
    if (bid[i << 1] || bid[i << 1 | 1]) {
      for (fl = 0; fl < 2; ++fl)
        if (!bid[i << 1 | fl]) {
          ans[i] = a[fl][1];
          solve(i + 1, 0);
          return;
        }
    }
    fl = (a[1][1] == 1);
    int sz = gg[i << 1 | fl].size();
    ans[i] = a[fl][1];
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      if (u & 1)
        vis[u >> 1] = 2;
      else
        vis[u >> 1] = 1;
    }
    solve(i + 1, 0);
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      vis[u >> 1] = 0;
    }
    fl ^= 1;
    ans[i] = a[fl][1];
    sz = gg[i << 1 | fl].size();
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      if (u & 1)
        vis[u >> 1] = 2;
      else
        vis[u >> 1] = 1;
    }
    solve(i + 1, 0);
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      vis[u >> 1] = 0;
    }
    return;
  } else {
    if (vis[i]) {
      ans[i] = geta(vis[i] - 1, s[i] - 'a' + 1);
      if (ans[i] == 27) return;
      solve(i + 1, ans[i] == s[i] - 'a' + 1);
      if (ans[i] == s[i] - 'a' + 1) {
        ans[i] = geta(vis[i] - 1, s[i] - 'a' + 2);
        if (ans[i] == 27) return;
        solve(i + 1, 0);
      }
      return;
    }
    if (bid[i << 1] || bid[i << 1 | 1]) {
      for (fl = 0; fl < 2; ++fl)
        if (!bid[i << 1 | fl]) {
          ans[i] = geta(fl, s[i] - 'a' + 1);
          if (ans[i] == 27) return;
          solve(i + 1, ans[i] == s[i] - 'a' + 1);
          if (ans[i] == s[i] - 'a' + 1) {
            ans[i] = geta(fl, s[i] - 'a' + 2);
            if (ans[i] == 27) return;
            solve(i + 1, 0);
          }
          return;
        }
    }
    fl = geta(1, s[i] - 'a' + 1) < geta(0, s[i] - 'a' + 1);
    int sz = gg[i << 1 | fl].size();
    ans[i] = geta(fl, s[i] - 'a' + 1);
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      if (u & 1)
        vis[u >> 1] = 2;
      else
        vis[u >> 1] = 1;
    }
    solve(i + 1, 1);
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      vis[u >> 1] = 0;
    }
    if (s[i] - 'a' + 1 == M) return;
    int fl1 = geta(1, s[i] - 'a' + 2) < geta(0, s[i] - 'a' + 2);
    if (fl == fl1) {
      int sz = gg[i << 1 | fl].size();
      ans[i] = geta(fl, s[i] - 'a' + 2);
      for (int j = 1; j < sz; ++j) {
        int u = gg[i << 1 | fl][j];
        if (u & 1)
          vis[u >> 1] = 2;
        else
          vis[u >> 1] = 1;
      }
      solve(i + 1, 0);
      for (int j = 1; j < sz; ++j) {
        int u = gg[i << 1 | fl][j];
        vis[u >> 1] = 0;
      }
    }
    fl ^= 1;
    ans[i] = geta(fl, s[i] - 'a' + 1);
    if (ans[i] == 27) return;
    sz = gg[i << 1 | fl].size();
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      if (u & 1)
        vis[u >> 1] = 2;
      else
        vis[u >> 1] = 1;
    }
    solve(i + 1, 0);
    for (int j = 1; j < sz; ++j) {
      int u = gg[i << 1 | fl][j];
      vis[u >> 1] = 0;
    }
    return;
  }
}
int main() {
  scanf("%s", s + 1);
  M = strlen(s + 1);
  register int i, j, u, v;
  a[0][0] = a[1][0] = 0;
  for (i = 1; i <= M; ++i)
    if (s[i] == 'V')
      a[0][++a[0][0]] = i;
    else
      a[1][++a[1][0]] = i;
  scanf("%d%d", &n, &m);
  if (a[0][0] == 0) {
    for (i = 1; i <= n; ++i) bid[i << 1] = 1;
  }
  if (a[1][0] == 0) {
    for (i = 1; i <= n; ++i) bid[i << 1 | 1] = 1;
  }
  a[0][++a[0][0]] = 27;
  a[1][++a[1][0]] = 27;
  for (i = 1; i <= m; ++i) {
    scanf("%d%s", &u, s + 1);
    if (s[1] == 'V')
      u = u << 1;
    else
      u = u << 1 | 1;
    scanf("%d%s", &v, s + 1);
    if (s[1] == 'V')
      v = v << 1;
    else
      v = v << 1 | 1;
    g[u][v] = 1;
    g[v ^ 1][u ^ 1] = 1;
  }
  for (i = 2; i <= n * 2 + 1; ++i)
    for (j = 2; j <= n * 2 + 1; ++j)
      if (g[i][j]) G[i].push_back(j);
  for (i = 2; i <= n * 2 + 1; ++i) {
    memset(vis, 0, sizeof vis);
    memset(gs, 0, sizeof gs);
    dfs(i, i);
  }
  for (i = 1; i <= n; ++i)
    if (bid[i << 1] && bid[i << 1 | 1]) {
      puts("-1");
      return 0;
    }
  memset(vis, 0, sizeof vis);
  scanf("%s", s + 1);
  solve(1, 1);
  puts("-1");
  return 0;
}
