#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
typename T::value_type arr_sum(const T& v, int n) {
  typename T::value_type sum = 0;
  for (int i = (0); i < (n); ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct Z {
  int p1;
  int s1;
  int p2;
  int s2;
};
vector<vector<int>> gin;
vector<vector<int>> gout;
vector<int> used;
vector<int> order;
int c_size = 0;
vector<vector<int>> comps;
void dfs(int t) {
  used[t] = 1;
  for (auto i : gout[t]) {
    if (!used[i]) {
      dfs(i);
    }
  }
  order.push_back(t);
}
void dfs2(int t) {
  used[t] = 1;
  comps[c_size - 1].push_back(t);
  for (auto i : gin[t]) {
    if (!used[i]) {
      dfs2(i);
    }
  }
}
int l, n;
int check_2sat() {
  used.assign(2 * n, 0);
  for (int i = (0); i < (2 * n); ++i) {
    if (!used[i]) {
      dfs(i);
    }
  }
  used.assign(2 * n, 0);
  for (int i = (0); i < (2 * n); ++i) {
    int v = order[2 * n - 1 - i];
    if (used[v]) {
      continue;
    }
    ++c_size;
    comps.resize(c_size);
    if (!used[v]) {
      dfs2(v);
    }
  }
  vector<int> cl(2 * n);
  for (int i = (0); i < (comps.size()); ++i) {
    for (auto j : comps[i]) {
      cl[j] = i;
    }
  }
  for (int i = 0; i < gout.size(); i += 2) {
    if (cl[i] == cl[i + 1]) {
      return 0;
    }
  }
  return 1;
}
vector<int> v;
inline void add(int x, int y) {
  gout[x].push_back(y);
  gin[y].push_back(x);
}
vector<Z> rules;
int build(const string& s) {
  comps.resize(c_size = 0);
  gin.resize(0);
  gin.resize(2 * n);
  gout.resize(0);
  gout.resize(2 * n);
  order.resize(0);
  vector<int> b(2, -1);
  for (auto i : rules) {
    b[0] = -1;
    b[1] = -1;
    if (s[i.p1] != '?') {
      b[0] = v[s[i.p1] - 'a'] ^ i.s1;
    }
    if (s[i.p2] != '?') {
      b[1] = v[s[i.p2] - 'a'] ^ i.s2;
    }
    if (b[0] == 0 && b[1] == 0) {
      return 0;
    }
    if (b[0] == 1 || b[1] == 1) {
      continue;
    }
    if (b[0] == 0) {
      add(2 * i.p2 + !i.s2, 2 * i.p2 + i.s2);
      continue;
    }
    if (b[1] == 0) {
      add(2 * i.p1 + !i.s1, 2 * i.p1 + i.s1);
      continue;
    }
    add(2 * i.p1 + !i.s1, 2 * i.p2 + i.s2);
    add(2 * i.p2 + !i.s2, 2 * i.p1 + i.s1);
  }
  return 1;
}
int main() {
  string v2;
  cin >> v2;
  l = v2.size();
  v.resize(l);
  for (int i = (0); i < (l); ++i) {
    v[i] = v2[i] == 'C';
  }
  int m;
  cin >> n >> m;
  gin.resize(2 * n);
  gout.resize(2 * n);
  for (int i = (0); i < (m); ++i) {
    string x, y;
    int a, b;
    cin >> a >> x >> b >> y;
    --a;
    --b;
    rules.push_back({a, x == "C", b, y == "V"});
  }
  string str;
  cin >> str;
  if (build(str)) {
    if (check_2sat()) {
      cout << str;
      return 0;
    }
  }
  string ans = str;
  int k = n - 1;
  while (k >= 0) {
    vector<int> u(2);
    int flag = 0;
    for (int j = (ans[k] - 'a' + 1); j < (l); ++j) {
      if (u[v[j]] == 1) {
        continue;
      }
      u[v[j]] = 1;
      ans[k] = 'a' + j;
      if (!build(ans)) {
        continue;
      }
      if (check_2sat()) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      break;
    }
    ans[k] = '?';
    --k;
  }
  if (k == -1) {
    cout << -1;
    return 0;
  }
  for (int i = (k + 1); i < (n); ++i) {
    int flag = 0;
    vector<int> u(2);
    for (int j = (0); j < (l); ++j) {
      if (u[v[j]] == 1) {
        continue;
      }
      u[v[j]] = 1;
      ans[i] = 'a' + j;
      if (!build(ans)) {
        continue;
      }
      if (check_2sat()) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
}
