#include <bits/stdc++.h>
using namespace std;
inline void setmin(int &x, int y) {
  if (y < x) x = y;
}
inline void setmax(int &x, int y) {
  if (y > x) x = y;
}
inline void setmin(long long &x, long long y) {
  if (y < x) x = y;
}
inline void setmax(long long &x, long long y) {
  if (y > x) x = y;
}
const int N = 200 * 2;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
string types;
int min_V = -1, min_C = -1;
vector<int> g[N], gr[N];
bool type[N];
void dfs(int u) {
  type[u] = true;
  for (int v : g[u])
    if (!type[v]) dfs(v);
}
bool used[N];
vector<int> order;
int comp[N];
void dfs1(int u) {
  used[u] = true;
  for (int v : g[u])
    if (!used[v] && !type[v] && !type[v ^ 1]) dfs1(v);
  order.push_back(u);
}
void dfs2(int u, int c) {
  used[u] = true;
  comp[u] = c;
  for (int v : gr[u])
    if (!used[v] && !type[v] && !type[v ^ 1]) dfs2(v, c);
}
set<int> G[N];
bool d[N][N];
void dfs3(int u, int s) {
  d[s][u] = true;
  for (int v : G[u]) dfs3(v, s);
}
bool check(string &s, int n, int len) {
  fill(type, type + n * 2, false);
  for (int i = 0; i < n; i++)
    if (s[i] != '.' && !type[i * 2 + (types[s[i] - 'a'] != 'V')])
      dfs(i * 2 + (types[s[i] - 'a'] != 'V'));
  for (int i = 0; i < n; i++)
    if (type[i * 2] && type[i * 2 + 1]) return false;
  bool ok = true;
  for (int i = 0; i < n; i++)
    if (s[i] == '.') ok = false;
  if (ok) return true;
  for (int i = 0; i < n; i++) {
    if (s[i] != '.') continue;
    if (type[i * 2])
      s[i] = char('a' + min_V);
    else if (type[i * 2 + 1])
      s[i] = char('a' + min_C);
  }
  order.clear();
  fill(used, used + n * 2, false);
  for (int i = 0; i < n * 2; i++)
    if (!used[i] && !type[i] && !type[i ^ 1]) dfs1(i);
  reverse(order.begin(), order.end());
  int c = 0;
  fill(comp, comp + n * 2, -1);
  fill(used, used + n * 2, false);
  for (int i : order)
    if (!used[i]) dfs2(i, c++);
  for (int i = 0; i < n; i++) {
    if (type[i * 2] || type[i * 2 + 1]) continue;
    if (comp[i * 2] == comp[i * 2 + 1]) return false;
  }
  for (int i = 0; i < n * 2; i++) {
    if (type[i] || type[i ^ 1]) continue;
    for (int j : g[i])
      if (!type[j] && !type[j ^ 1] && comp[i] != comp[j])
        G[comp[i]].insert(comp[j]);
  }
  for (int i = 0; i < c; i++) dfs3(i, i);
  for (int i = 0; i < n; i++) {
    if (type[i * 2] || type[i * 2 + 1]) continue;
    if (d[comp[i * 2]][comp[i * 2 + 1]]) {
      s[i] = char('a' + min_C);
      dfs(i * 2 + 1);
      for (int j = 0; j < n; j++)
        if (s[j] == '.' && (type[j * 2] || type[j * 2 + 1])) {
          if (type[j * 2])
            s[j] = char('a' + min_V);
          else
            s[j] = char('a' + min_C);
        }
    } else if (d[comp[i * 2 + 1]][comp[i * 2]]) {
      s[i] = char('a' + min_V);
      dfs(i * 2);
      for (int j = 0; j < n; j++)
        if (s[j] == '.' && (type[j * 2] || type[j * 2 + 1])) {
          if (type[j * 2])
            s[j] = char('a' + min_V);
          else
            s[j] = char('a' + min_C);
        }
    } else {
      s[i] = char('a' + min(min_V, min_C));
      dfs(i * 2 + (min(min_V, min_C) != min_V));
      for (int j = 0; j < n; j++)
        if (s[j] == '.' && (type[j * 2] || type[j * 2 + 1])) {
          if (type[j * 2])
            s[j] = char('a' + min_V);
          else
            s[j] = char('a' + min_C);
        }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  cin >> types;
  int len = (int)types.size();
  for (int i = 0; i < len; i++)
    if (types[i] == 'V') {
      min_V = i;
      break;
    }
  for (int i = 0; i < len; i++)
    if (types[i] == 'C') {
      min_C = i;
      break;
    }
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int p1, p2;
    char c1, c2;
    cin >> p1 >> c1 >> p2 >> c2;
    p1--;
    p2--;
    g[p1 * 2 + (c1 != 'V')].push_back(p2 * 2 + (c2 != 'V'));
    g[p2 * 2 + (c2 == 'V')].push_back(p1 * 2 + (c1 == 'V'));
    gr[p2 * 2 + (c2 != 'V')].push_back(p1 * 2 + (c1 != 'V'));
    gr[p1 * 2 + (c1 == 'V')].push_back(p2 * 2 + (c2 == 'V'));
  }
  string s;
  cin >> s;
  if (check(s, n, len)) {
    cout << s << "\n";
    return 0;
  }
  if (min_V < min_C) {
    for (int i = n - 1; i > -1; i--) {
      string t = s;
      for (int j = s[i] - 'a' + 1; j < len; j++)
        if (types[j] == 'V') {
          t[i] = char('a' + j);
          for (int k = i + 1; k < n; k++)
            t[k] = (min_C != -1 ? '.' : char('a' + min_V));
          if (check(t, n, len)) {
            cout << t << "\n";
            return 0;
          }
          break;
        }
      for (int j = s[i] - 'a' + 1; j < len; j++)
        if (types[j] == 'C') {
          t[i] = char('a' + j);
          for (int k = i + 1; k < n; k++)
            t[k] = (min_V != -1 ? '.' : char('a' + min_C));
          if (check(t, n, len)) {
            cout << t << "\n";
            return 0;
          }
          break;
        }
    }
  } else {
    for (int i = n - 1; i > -1; i--) {
      string t = s;
      for (int j = s[i] - 'a' + 1; j < len; j++)
        if (types[j] == 'C') {
          t[i] = char('a' + j);
          for (int k = i + 1; k < n; k++)
            t[k] = (min_V != -1 ? '.' : char('a' + min_C));
          if (check(t, n, len)) {
            cout << t << "\n";
            return 0;
          }
          break;
        }
      for (int j = s[i] - 'a' + 1; j < len; j++)
        if (types[j] == 'V') {
          t[i] = char('a' + j);
          for (int k = i + 1; k < n; k++)
            t[k] = (min_C != -1 ? '.' : char('a' + min_V));
          if (check(t, n, len)) {
            cout << t << "\n";
            return 0;
          }
          break;
        }
    }
  }
  cout << -1 << "\n";
  return 0;
}
