#include <bits/stdc++.h>
using namespace std;
int n, m, l;
int type[26], a[205];
vector<pair<int, int> > rules[205][2];
int x, y;
int dp[205][205];
int result[205], mark[205][2];
pair<int, int> q[205];
int check(int p, int t, int &x) {
  if (mark[p][t] > 1) {
    mark[p][t]--;
    return 1;
  }
  int y = x;
  q[x++] = make_pair(p, t);
  while (y < x) {
    int u = q[y].first;
    int v = q[y].second;
    y++;
    for (int i = 0; i < rules[u][v].size(); i++) {
      int eu = rules[u][v][i].first;
      int ev = rules[u][v][i].second;
      if (mark[eu][1 - ev] != 0) {
        return 0;
      }
      if (mark[eu][ev] == 0) {
        mark[eu][ev]++;
        q[x++] = make_pair(eu, ev);
      }
    }
  }
  return 1;
}
int TRY(int p, int isEqual, int x) {
  if (x + 1 == p && dp[p][p]) {
    return 0;
  }
  if (x + 1 == p) {
    dp[p][p] = 1;
  }
  if (p > n) {
    for (int i = 1; i <= n; i++) {
      cout << char(result[i] + 'a');
    }
    return 1;
  }
  int dd[2];
  dd[0] = dd[1] = 0;
  int start = (isEqual == 1) ? a[p] : 0;
  for (int i = start; i < l; i++) {
    if (mark[p][1 - type[i]] == 0 && dd[type[i]] == 0) {
      int newX = x;
      mark[p][type[i]]++;
      if (check(p, type[i], newX)) {
        result[p] = i;
        if (isEqual == 0 || i > start) {
          dd[type[i]] = 1;
        }
        if (TRY(p + 1, isEqual & (i == start), newX)) {
          return 1;
        }
      }
      for (int j = x; j < newX; j++) {
        mark[q[j].first][q[j].second]--;
      }
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  string st;
  cin >> st;
  l = st.size();
  for (int i = 0; i < l; i++) {
    type[i] = st[i] == 'V';
  }
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int p1, p2;
    char t1, t2;
    cin >> p1 >> t1 >> p2 >> t2;
    rules[p1][(t1 == 'V')].push_back(make_pair(p2, (t2 == 'V')));
  }
  cin >> st;
  for (int i = 0; i < n; i++) {
    a[i + 1] = st[i] - 'a';
  }
  if (!TRY(1, 1, 0)) {
    cout << -1;
  }
}
