#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 500;
vector<int> g[N], gr[N], add[N], addr[N], ord;
int usedLet[N];
int type[N], used[N], cmp[N], cur_cmp;
int n, m, alpha;
string s, ans;
void dfs(int v) {
  used[v] = 1;
  for (int to : g[v])
    if (!used[to]) dfs(to);
  for (int to : add[v])
    if (!used[to]) dfs(to);
  ord.push_back(v);
}
void get(int v) {
  cmp[v] = cur_cmp;
  for (int to : gr[v])
    if (!cmp[to]) get(to);
  for (int to : addr[v])
    if (!cmp[to]) get(to);
}
void add_g(int v, int u) {
  g[v].push_back(u);
  gr[u].push_back(v);
}
void add_add(int v, int u) {
  add[v].push_back(u);
  addr[u].push_back(v);
}
bool can_build() {
  memset(used, 0, sizeof used);
  memset(cmp, 0, sizeof cmp);
  ord.clear();
  cur_cmp = 0;
  for (int v = 0; v < 2 * n; v++)
    if (!used[v]) dfs(v);
  reverse((ord).begin(), (ord).end());
  for (int v : ord)
    if (!cmp[v]) cur_cmp++, get(v);
  for (int v = 0; v < n; v++)
    if (cmp[2 * v] == cmp[2 * v + 1]) return false;
  return true;
}
void rec(int i, bool in_pref) {
  if (!can_build()) return;
  if (i == n) {
    cout << ans;
    exit(0);
  }
  int v = 2 * i + type[s[i] - 'a'];
  if (in_pref) {
    ans[i] = s[i];
    add_add(v ^ 1, v);
    rec(i + 1, true);
    add[v ^ 1].pop_back();
    addr[v].pop_back();
  }
  usedLet[v] = 0;
  int first;
  if (in_pref)
    first = s[i] - 'a' + 1;
  else
    first = 0;
  for (int cur = first; cur < alpha; cur++) {
    v = 2 * i + type[cur];
    if (usedLet[v]) continue;
    ans[i] = cur + 'a';
    add_add(v ^ 1, v);
    rec(i + 1, false);
    add[v ^ 1].pop_back();
    addr[v].pop_back();
    usedLet[v] = 1;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  string tmp;
  cin >> tmp;
  alpha = (int)(tmp).size();
  for (int i = 0; i < alpha; i++) type[i] = (tmp[i] == 'C');
  cin >> n >> m;
  while (m--) {
    int i1, i2;
    char p1, p2;
    cin >> i1 >> p1 >> i2 >> p2;
    --i1, --i2;
    int v1 = 2 * i1 + (p1 == 'C'), v2 = 2 * i2 + (p2 == 'C');
    add_g(v1, v2);
    add_g(v2 ^ 1, v1 ^ 1);
  }
  ans.resize(n);
  cin >> s;
  if (!can_build()) {
    cout << -1;
    return 0;
  }
  rec(0, true);
  cout << -1;
  return 0;
}
