#include <bits/stdc++.h>
using namespace std;
int const N = 200 + 20;
int n, m, L, g[N << 1][N << 1];
bool have[2];
string T, s, t;
inline bool f(char ch) { return ch == 'C'; }
inline bool ok(int i, int j) {
  int x = (i << 1) ^ f(T[t[i] - 'a']), y = (j << 1) ^ f(T[t[j] - 'a']);
  return !g[x][y ^ 1] && !g[y][x ^ 1];
}
void solve(int i, bool gr) {
  if (i == n) {
    cout << t << '\n';
    exit(0);
  }
  bool check[2] = {0, 0};
  for (char ch = (gr ? 'a' : s[i]); ch < 'a' + L; ch++) {
    if (check[f(ch)]) {
      continue;
    }
    t[i] = ch;
    bool fl = 1;
    for (int j = 0; j <= i; j++) {
      fl &= ok(i, j);
    }
    if (fl) {
      solve(i + 1, gr || (ch > s[i]));
    }
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  L = T.size();
  for (int i = 0; i < L; i++) {
    have[f(T[i])] = 1;
  }
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char ca, cb;
    cin >> a >> ca >> b >> cb;
    a--, b--;
    int x = (a << 1) ^ f(ca), y = (b << 1) ^ f(cb);
    g[x][y] = g[y ^ 1][x ^ 1] = 1;
  }
  if (!have[0] || !have[1]) {
    for (int i = 0; i < n; i++) {
      g[(i << 1) ^ have[0]][(i << 1) ^ have[1]] = 1;
    }
  }
  cin >> s;
  t = string(n, '.');
  for (int k = 0; k < (n << 1); k++) {
    for (int i = 0; i < (n << 1); i++) {
      for (int j = 0; j < (n << 1); j++) {
        g[i][j] |= g[i][k] && g[k][j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (g[(i << 1)][(i << 1) ^ 1] && g[(i << 1) ^ 1][(i << 1)]) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x = (i << 1), y = (j << 1);
    }
  }
  solve(0, 0);
  cout << "-1\n";
  return 0;
}
