#include <bits/stdc++.h>
using namespace std;
int n, m, k, cla[30], a[200 + 5], hd[2 * 200 + 5], len = 0;
char s[30];
struct Edge {
  int v, net;
} e[2 * 160000 + 5];
void addi(int u, int v) {
  e[len] = (Edge){v, hd[u]};
  hd[u] = len++;
}
void add(int u, int v) {
  addi(u, v);
  addi(v <= n ? n + v : v - n, u <= n ? n + u : u - n);
}
template <class T>
void read(T &x) {
  char ch;
  bool ok;
  for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') ok = 1;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (ok) x = -x;
}
int col[200 + 5], col_cpy[200 + 5];
bool dfs(int u, int ty) {
  if (col_cpy[u] != -1) return col_cpy[u] == ty;
  col_cpy[u] = ty;
  for (int i = hd[ty * n + u]; ~i; i = e[i].net) {
    int v = e[i].v;
    if (!(v > n ? dfs(v - n, 1) : dfs(v, 0))) return 0;
  }
  return 1;
}
int fl = 0, mx[2];
bool chk(int x, int ty) {
  if (fl || ty) return 1;
  for (int i = (x), en = (n); i <= en; ++i) {
    if (col_cpy[i] == -1) {
      if (mx[!cla[a[i]]] > a[i]) return 1;
      continue;
    }
    if (mx[col_cpy[i]] > a[i]) return 1;
    if (mx[col_cpy[i]] < a[i]) return 0;
  }
  return 1;
}
bool chk(int x, int ty, int tty) {
  memcpy(col_cpy, col, sizeof col);
  if (dfs(x, ty) && chk(x + 1, tty)) {
    memcpy(col, col_cpy, sizeof col_cpy);
    return 1;
  }
  return 0;
}
int as[200 + 5];
int main() {
  memset(hd, -1, sizeof hd);
  scanf("%s", s + 1);
  k = strlen(s + 1);
  int mn = 0;
  for (int i = (1), en = (k); i <= en; ++i) {
    cla[i] = s[i] == 'C';
    if (cla[i] != cla[1] && !mn) mn = i;
    mx[cla[i]] = max(mx[cla[i]], i);
  }
  read(n);
  read(m);
  for (int i = (1), en = (m); i <= en; ++i) {
    int x, y, xx, yy;
    char c;
    read(x);
    cin >> c;
    y = c == 'C';
    read(xx);
    cin >> c;
    yy = c == 'C';
    add(x + n * y, xx + n * yy);
    if (y != yy && !mx[yy]) {
      puts("-1");
      return 0;
    }
  }
  memset(col, -1, sizeof col);
  for (int i = (1), en = (n); i <= en; ++i) {
    char c;
    cin >> c;
    a[i] = c - 'a' + 1;
  }
  for (int i = (1), en = (n); i <= en; ++i) {
    if (fl) {
      if (chk(i, cla[1], 1))
        as[i] = 1;
      else if (chk(i, !cla[1], 1))
        as[i] = mn;
      else {
        puts("-1");
        return 0;
      }
    } else {
      int tem = 0, tem1 = 0;
      for (int j = (a[i] + 1), en = (k); j <= en; ++j) {
        if (cla[j] != cla[a[i]]) {
          if (!tem) tem = j;
        } else {
          if (!tem1) tem1 = j;
        }
      }
      if (chk(i, cla[a[i]], 0))
        as[i] = a[i];
      else {
        if (tem > tem1) swap(tem, tem1);
        if (tem && chk(i, cla[tem], 1))
          as[i] = tem;
        else if (tem1 && chk(i, cla[tem1], 1))
          as[i] = tem1;
        else {
          puts("-1");
          return 0;
        }
      }
    }
    fl |= as[i] > a[i];
  }
  for (int i = (1), en = (n); i <= en; ++i) putchar('a' + as[i] - 1);
  return 0;
}
