#include <bits/stdc++.h>
using namespace std;
const int maxn = 310;
int n, m;
vector<pair<int, int> > D;
vector<int> DV;
vector<int> DC;
vector<int> G[maxn * 2];
vector<int> F[maxn * 2];
map<char, int> E;
bool mark[maxn * 2];
long long K[200000 + 5];
int S[maxn * 4], c;
bool dfs(int x) {
  if (mark[x ^ 1]) return false;
  if (mark[x]) return true;
  mark[x] = true;
  S[c++] = x;
  for (int i = 0; i < G[x].size(); i++)
    if (!dfs(G[x][i])) return false;
  return true;
}
int cal(char a) {
  if (a == 'C')
    return 0;
  else
    return 1;
}
void init(int n) {
  for (int i = 0; i < n * 2; i++) G[i].clear();
  memset(mark, 0, sizeof(mark));
}
void add_clause(int x, int xval, int y, int yval) {
  x = x * 2 + xval;
  y = y * 2 + yval;
  G[x].push_back(y ^ 1);
  G[y].push_back(x ^ 1);
}
bool solve1() {
  for (int i = 0; i < n * 2; i += 2)
    if (!mark[i] && !mark[i + 1]) {
      c = 0;
      if (!dfs(i)) {
        while (c > 0) mark[S[--c]] = false;
        if (!dfs(i + 1)) return false;
      }
    }
  return true;
}
bool solve2() {
  for (int i = 0; i < n * 2; i += 2)
    if (!mark[i] && !mark[i + 1]) {
      c = 0;
      if (!dfs(i + 1)) {
        while (c > 0) mark[S[--c]] = false;
        if (!dfs(i)) return false;
      }
    }
  return true;
}
int main() {
  string a;
  cin >> a;
  int tc = 0;
  int tv = 0;
  memset(mark, 0, sizeof(mark));
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 'V') {
      E[i + 'a'] = 1;
      tv = 1;
    } else {
      E[i + 'a'] = 0;
      tc = 1;
    }
  }
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int o, b;
    char c, d;
    cin >> o >> c >> b >> d;
    int k = cal(c);
    int f = cal(d);
    f = f ^ 1;
    add_clause(o - 1, k, b - 1, f);
  }
  if (tc == 0) {
    for (int i = 0; i < n; i++) {
      G[i * 2].push_back(i * 2 + 1);
    }
  }
  if (tv == 0) {
    for (int i = 0; i < n; i++) {
      G[2 * i + 1].push_back(2 * i);
    }
  }
  for (int i = 0; i < 500; i++) {
    F[i] = G[i];
  }
  string k;
  cin >> k;
  int w;
  int ks = 0;
  for (int l = 0; l < n; l++) {
    if (E[k[l]] == 0)
      G[l * 2 + 1].push_back(l * 2);
    else
      G[l * 2].push_back(l * 2 + 1);
  }
  if (solve1()) {
    cout << k << endl;
    return 0;
  }
  for (w = n - 1; w >= 0; w--) {
    init(n);
    for (int i = 0; i < 500; i++) G[i] = F[i];
    for (int l = 0; l < w; l++) {
      if (E[k[l]] == 0)
        G[l * 2 + 1].push_back(l * 2);
      else
        G[l * 2].push_back(l * 2 + 1);
    }
    if (a[0] == 'C') {
      int firsc = 0;
      int firsv = 0;
      for (int kd = k[w] - 'a' + 1; kd < a.size(); kd++) {
        int q;
        memset(mark, 0, sizeof(mark));
        if (E[kd + 'a'] == 0 && firsc == 0) {
          firsc = 1;
          G[w * 2 + 1].push_back(w * 2);
          q = w * 2 + 1;
        } else if (E[kd + 'a'] == 1 && firsv == 0) {
          firsv = 1;
          G[w * 2].push_back(1 + w * 2);
          q = w * 2;
        } else
          continue;
        if (solve1()) {
          ks = kd + 1;
          break;
        } else {
          G[q].erase(G[q].end() - 1);
        }
      }
      if (ks != 0) break;
    } else {
      int firsc = 0;
      int firsv = 0;
      for (int kd = k[w] - 'a' + 1; kd < a.size(); kd++) {
        int q;
        memset(mark, 0, sizeof(mark));
        if (E[kd + 'a'] == 0 && firsc == 0) {
          firsc = 1;
          G[w * 2 + 1].push_back(w * 2);
          q = w * 2 + 1;
        } else if (E[kd + 'a'] == 1 && firsv == 0) {
          firsv = 1;
          G[w * 2].push_back(1 + w * 2);
          q = w * 2;
        } else
          continue;
        if (solve2()) {
          ks = kd + 1;
          break;
        } else {
          G[q].erase(G[q].end() - 1);
        }
      }
    }
    if (ks != 0) break;
  }
  int minc, minv;
  int firstc, firstv;
  firstc = 0;
  firstv = 0;
  for (int p = 0; p < a.size(); p++) {
    if (E[p + 'a'] == 0 && firstc == 0) {
      minc = p;
      firstc = 1;
    } else if (firstv == 0 && E[p + 'a'] == 1) {
      minv = p;
      firstv = 1;
    }
  }
  char d = 'a' + minc;
  char s = 'a' + minv;
  if (ks) {
    for (int i = 0; i < w; i++) {
      cout << k[i];
    }
    char dq = 'a' + ks - 1;
    cout << dq;
    for (int i = w + 1; i < k.size(); i++) {
      if (mark[2 * i])
        cout << d;
      else
        cout << s;
    }
  } else
    cout << -1 << endl;
}
