#include <bits/stdc++.h>
using namespace std;
bool G[1000][1000], can[100];
int pos[1000], q;
bool nable(int x, int y) {
  if (G[x][y ^ 1]) assert(G[y][x ^ 1]);
  if (G[y][x ^ 1]) assert(G[x][y ^ 1]);
  return G[x][y ^ 1] || G[y][x ^ 1];
}
int isc(char ch) { return ch == 'C'; }
bool check(int x, char st, string &ans, const string &let) {
  for (int i = 0; i <= 1; i++) {
    can[i] = true;
    pos[x] = x * 2 + i;
    for (int j = 0; j <= x; j++)
      if (nable(pos[x], pos[j])) {
        can[i] = false;
        break;
      }
  }
  if (!can[0] && !can[1]) return false;
  ans[x] = st;
  while (!can[isc(let[ans[x] - 'a'])] && ans[x] < q) ans[x]++;
  if (ans[x] >= q) return false;
  pos[x] = x * 2 + isc(let[ans[x] - 'a']);
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  string let;
  int n, m;
  cin >> let >> n >> m;
  q = let.length() + 'a';
  for (int i = 1; i <= m; i++) {
    int pos1, pos2;
    char t1, t2;
    cin >> pos1 >> t1 >> pos2 >> t2;
    --pos1 *= 2;
    --pos2 *= 2;
    pos1 += isc(t1);
    pos2 += isc(t2);
    G[pos1][pos2] = G[pos2 ^ 1][pos1 ^ 1] = true;
  }
  for (int k = 0; k < n * 2; k++)
    for (int i = 0; i < n * 2; i++)
      for (int j = 0; j < n * 2; j++) G[i][j] |= G[i][k] && G[k][j];
  string s;
  cin >> s;
  int i;
  for (int i = 0; i < n; i++) pos[i] = i * 2 + isc(let[s[i] - 'a']);
  for (i = 0; i < n; i++) {
    bool flag = true;
    for (int j = 0; j <= i; j++)
      if (nable(pos[i], pos[j])) {
        flag = false;
        break;
      }
    if (!flag) break;
  }
  if (i >= n) {
    cout << s;
    return 0;
  }
  for (; i >= 0; i--) {
    if (!check(i, s[i] + 1, s, let)) continue;
    for (int j = i + 1; j < n; j++)
      if (!check(j, 'a', s, let)) {
        cout << -1;
        return 0;
      }
    cout << s;
    return 0;
  }
  cout << -1;
}
