/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 200 + 5;
int n, m, l, mark[2 * N];
vector<int> adj[2 * N];
string s, t;
bool a[N];

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = 0; i < l; i++)
		a[i] = (s[i] == 'V');

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int p1, p2;
		char c1, c2;
		cin >> p1 >> c1 >> p2 >> c2;
		adj[p1 - 1 << 1 ^ (c1 == 'V')].push_back(p2 - 1 << 1 ^ (c2 == 'V'));
	}

	cin >> s;
	t.resize(n);
}

bool solve(int p = 0, bool bad = true) {
	if (p == n)
		return true;
	if (!mark[p << 1] && !mark[p << 1 ^ 1]) {
		for (auto x: {a[0], !a[0]}) {
			mark[p << 1 ^ x] = true;
			if (solve(p, bad))
				return true;
			mark[p << 1 ^ x] = false;
		}
		return false;
	}
	for (int i = bad? s[p] - 'a': 0; i < l; i++)
		if (mark[p << 1 ^ a[i]]) {
			bool ok = true;
			t[p] = 'a' + i;
			vector<int> vec;
			for (auto v: adj[p << 1 ^ a[i]])
				if (!mark[v] && !mark[v ^ 1]) {
					mark[v] = true;
					vec.push_back(v);
				}
				else
					ok &= !mark[v ^ 1];
			if (ok && solve(p + 1, bad && (s[p] == t[p])))
				return true;
			for (auto v: vec)
				mark[v] = false;
		}
	return false;
}

void writeOutput() {
	if (solve()) {
		cout << t << endl;
		return;
	}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), writeOutput();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 200 + 5, M = 4 * N * N;
int n, m, l, c, p1[M], p2[M], mark[2 * N];
char x[2][2] = {{'*', '*'}, {'*', '*'}};
vector<int> adj[2 * N][2], topol;
bool a[26 + 4], a1[M], a2[M];
string s;

void add_clause(int u, int v) {
	adj[u ^ 1][0].push_back(v);
	adj[v ^ 1][0].push_back(u);
	adj[u][1].push_back(v ^ 1);
	adj[v][1].push_back(u ^ 1);
}

void dfs_t(int u) {
	mark[u] = 1;
	for (auto v: adj[u][0])
		if (!mark[v])
			dfs_t(v);
	topol.push_back(u);
}

void dfs_c(int u) {
	mark[u] = c;
	for (auto v: adj[u][1])
		if (!mark[v])
			dfs_c(v);
}

bool check(int p) {
	topol.clear();
	for (int u = c = 0; u < 2 * n; u++) {
		adj[u][0].clear();
		adj[u][1].clear();
	}
	for (int u = 0; u < p; u++)
		add_clause(u << 1 ^ !a[s[u] - 'a'], u << 1 ^ !a[s[u] - 'a']);
	if (p < n)
		for (int i = 0; i < 2; i++)
			if (x[1][i] <= s[p])
				add_clause(p << 1 ^ i, p << 1 ^ i);
	for (int i = 0; i < m; i++)
		add_clause(p1[i] << 1 ^ a1[i], p2[i] << 1 ^ !a2[i]);
	memset(mark, 0, sizeof mark);
	for (int u = 0; u < 2 * n; u++)
		if (!mark[u])
			dfs_t(u);
	reverse(topol.begin(), topol.end());
	memset(mark, 0, sizeof mark);
	for (auto u: topol)
		if (!mark[u]) {
			c++;
			dfs_c(u);
		}
	for (int u = 0; u < n; u++)
		if (mark[u << 1] == mark[u << 1 ^ 1])
			return false;
	if (p == n)
		return true;
	for (int u = p + 1; u < n; u++)
		s[u] = x[0][mark[u << 1] > mark[u << 1 ^ 1]];
	for (int i = s[p] - 'a' + 1; i < l; i++)
		if (a[i] == (mark[p << 1] > mark[p << 1 ^ 1])) {
			s[p] = 'a' + i;
			return true;
		}
	return false;
}

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = 0; i < l; i++) {
		x[1][a[i] = (s[i] == 'V')] = 'a' + i;
		if (x[0][a[i]] == '*')
			x[0][a[i]] = 'a' + i;
	}
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		char c1, c2;
		cin >> p1[i] >> c1 >> p2[i] >> c2;

		p1[i]--;
		p2[i]--;
		a1[i] = (c1 == 'V');
		a2[i] = (c2 == 'V');
	}
	cin >> s;
}

void solve() {
	for (int i = n; ~i; i--)
		if (check(i)) {
			cout << s << endl;
			return;
		}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 200 + 5;
int n, m, l, mark[2 * N];
vector<int> adj[2 * N];
string s, t;
bool a[N];

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = 0; i < l; i++)
		a[i] = (s[i] == 'V');

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int p1, p2;
		char c1, c2;
		cin >> p1 >> c1 >> p2 >> c2;
		adj[2 * (p1 - 1) + (c1 == 'V')].push_back(2 * (p2 - 1) + (c2 == 'V'));
	}

	cin >> s;
	t.resize(n);
}

bool solve(int p = 0, bool bad = true) {
	if (p == n)
		return true;
	bool both = (!mark[p << 1] && !mark[p << 1 ^ 1]);
	for (int i = bad? s[p] - 'a': 0; i < l; i++)
		if (both || mark[p << 1 ^ a[i]]) {
			bool ok = true;
			t[p] = 'a' + i;
			vector<int> vec;
			if (both)
				mark[p << 1 ^ a[i]] = true;
			for (auto v: adj[p << 1 ^ a[i]])
				if (!mark[v] && !mark[v ^ 1]) {
					mark[v] = true;
					vec.push_back(v);
				}
				else
					ok &= !mark[v ^ 1];
			if (ok && solve(p + 1, bad && (s[p] == t[p])))
				return true;
			for (auto v: vec)
				mark[v] = false;
			if (both)
				mark[p << 1 ^ a[i]] = false;
		}
	return false;
}

void writeOutput() {
	if (solve()) {
		cout << t << endl;
		return;
	}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), writeOutput();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 2 * 200 + 5, M = N * N, K = 26 + 4;
int l, n, m, c, mark[N], a[K], b[N], nxt[K][2], x[2] = {-1, -1};
vector<int> adj[N][2], topol;
string s;

void add_clause(int u, int v) {
	adj[u ^ 1][0].push_back(v);
	adj[v ^ 1][0].push_back(u);
	adj[u][1].push_back(v ^ 1);
	adj[v][1].push_back(u ^ 1);
}

void dfs_t(int u) {
	mark[u] = 1;
	for (auto v: adj[u][0])
		if (!mark[v])
			dfs_t(v);
	topol.push_back(u);
}

void dfs_c(int u) {
	mark[u] = c;
	for (auto v: adj[u][1])
		if (!mark[v])
			dfs_c(v);
}

bool can() {
	topol.clear();
	memset(mark, 0, sizeof mark);
	for (int u = c = 0; u < 2 * n; u++)
		if (!mark[u])
			dfs_t(u);
	reverse(topol.begin(), topol.end());
	memset(mark, 0, sizeof mark);
	for (auto u: topol)
		if (!mark[u]) {
			c++;
			dfs_c(u);
		}

	for (int u = 0; u < n; u++)
		if (mark[u << 1] == mark[u << 1 ^ 1])
			return false;
	return true;
}

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = l - 1; ~i; i--) {
		nxt[i][0] = x[0];
		nxt[i][1] = x[1];
		a[i] = (s[i] == 'V');
		if (!~x[0] || a[x[0]] != a[i])
			x[1] = x[0];
		x[0] = i;
	}

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		char c1, c2;
		cin >> u >> c1 >> v >> c2;
		add_clause((--u <<= 1) ^= (c1 != 'V'), (--v <<= 1) ^= (c2 == 'V'));
	}
	cin >> s;
	for (int i = 0; i < n; i++) {
		b[i] = s[i] - 'a';
		add_clause(i << 1 ^ a[b[i]], i << 1 ^ a[b[i]]);
	}
	if (!~x[1])
		for (int i = 0; i < n; i++)
			add_clause(i << 1 ^ a[0], i << 1 ^ a[0]);
}

void solve() {
	if (can()) {
		cout << s << endl;
		return;
	}
	for (int i = n - 1; ~i; i--) {
		for (int k = 0; k < 2; k++) {
			adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
			adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
		}
		for (int j = 0; j < 2; j++)
			if (~nxt[b[i]][j]) {
				add_clause(i << 1 ^ j, i << 1 ^ j);
				if (can()) {
					s[i] = 'a' + nxt[b[i]][j];
					for (int p = i + 1; p < n; p++) {
						add_clause(p << 1 ^ a[0], p << 1 ^ a[0]);
						if (can()) {
							s[p] = 'a';
							continue;
						}
						s[p] = x[1];
						for (int k = 0; k < 2; k++) {
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
						}
					}
					cout << s << endl;
					return;
				}
				for (int k = 0; k < 2; k++) {
					adj[i << 1 ^ j ^ k][!k].pop_back();
					adj[i << 1 ^ j ^ k][!k].pop_back();
				}
			}
	}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 200 + 5;
int n, m, l, c, a[N], mark[2 * N];
vector<int> adj[2 * N], tmp;
string s, t;

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = 0; i < l; i++) {
		a[i] = (s[i] == 'V');
		if (tmp.empty() || (a[i] != tmp[0] && tmp.size() == 1))
			tmp.push_back(a[i]);
	}

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int p1, p2;
		char c1, c2;
		cin >> p1 >> c1 >> p2 >> c2;
		adj[p1 - 1 << 1 ^ (c1 == 'V')].push_back(p2 - 1 << 1 ^ (c2 == 'V'));
	}
	cin >> s;
	t.resize(n);
}

bool solve(int p = 0, bool ok = false) {
	if (p == n)
		return true;
	if (!mark[p << 1] && !mark[p << 1 ^ 1]) {
		for (auto x: tmp) {
			mark[p << 1 ^ x] = true;
			if (solve(p, ok))
				return true;
			mark[p << 1 ^ x] = false;
		}
		return false;
	}
	for (int i = (s[p] - 'a') * !ok; i < l; i++)
		if (mark[p << 1 ^ a[i]]) {
			t[p] = 'a' + i;
			bool can = true;
			vector<int> vec;
			for (auto v: adj[p << 1 ^ a[i]])
				if (!mark[v] && !mark[v ^ 1]) {
					mark[v] = true;
					vec.push_back(v);
				}
				else
					can &= !mark[v ^ 1];
			if (can && solve(p + 1, ok || (s[p] < t[p])))
				return true;
			for (auto v: vec)
				mark[v] = false;
		}
	return false;
}

void writeOutput() {
	if (solve()) {
		cout << t << endl;
		return;
	}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), writeOutput();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 2 * 200 + 5, M = N * N, K = 26 + 4;
int l, n, m, c, mark[N], a[K], b[N], nxt[K][2], x[2] = {-1, -1};
vector<int> adj[N][2], topol;
string s;

void add_clause(int u, int v) {
	adj[u ^ 1][0].push_back(v);
	adj[v ^ 1][0].push_back(u);
	adj[u][1].push_back(v ^ 1);
	adj[v][1].push_back(u ^ 1);
}

void dfs_t(int u) {
	mark[u] = 1;
	for (auto v: adj[u][0])
		if (!mark[v])
			dfs_t(v);
	topol.push_back(u);
}

void dfs_c(int u) {
	mark[u] = c;
	for (auto v: adj[u][1])
		if (!mark[v])
			dfs_c(v);
}

bool can() {
	topol.clear();
	memset(mark, 0, sizeof mark);
	for (int u = c = 0; u < 2 * n; u++)
		if (!mark[u])
			dfs_t(u);
	reverse(topol.begin(), topol.end());
	memset(mark, 0, sizeof mark);
	for (auto u: topol)
		if (!mark[u]) {
			c++;
			dfs_c(u);
		}

	for (int u = 0; u < n; u++)
		if (mark[u << 1] == mark[u << 1 ^ 1])
			return false;
	return true;
}

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = l - 1; ~i; i--) {
		nxt[i][0] = x[0];
		nxt[i][1] = x[1];
		a[i] = (s[i] == 'V');
		if (!~x[0] || a[x[0]] != a[i])
			x[1] = x[0];
		x[0] = i;
	}

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		char c1, c2;
		cin >> u >> c1 >> v >> c2;
		add_clause((--u <<= 1) ^= (c1 != 'V'), (--v <<= 1) ^= (c2 == 'V'));
	}
	cin >> s;
	for (int i = 0; i < n; i++) {
		b[i] = s[i] - 'a';
		add_clause(i << 1 ^ a[b[i]], i << 1 ^ a[b[i]]);
	}
	if (!~x[1])
		for (int i = 0; i < n; i++)
			add_clause(i << 1 ^ a[0], i << 1 ^ a[0]);
}

void solve() {
	for (int i = n; ~i; i--) {
		if (i < n)
			for (int k = 0; k < 2; k++) {
				adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
				adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
			}
		for (int j = 0; j < 2; j++)
			if (~nxt[b[i]][j]) {
				add_clause(i << 1 ^ j, i << 1 ^ j);
				if (can()) {
					s[i] = 'a' + nxt[b[i]][j];
					for (int p = i + 1; p < n; p++) {
						add_clause(p << 1 ^ a[0], p << 1 ^ a[0]);
						if (can()) {
							s[p] = 'a';
							continue;
						}
						s[p] = x[1];
						for (int k = 0; k < 2; k++) {
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
						}
					}
					cout << s << endl;
					return;
				}
				for (int k = 0; k < 2; k++) {
					adj[i << 1 ^ j ^ k][!k].pop_back();
					adj[i << 1 ^ j ^ k][!k].pop_back();
				}
			}
	}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 2 * 200 + 5, M = N * N, K = 26 + 4;
int l, n, m, c, mark[N], a[K], b[N], nxt[K][2], x[2] = {-1, -1};
vector<int> adj[N][2], topol;
string s;

void add_clause(int u, int v) {
	adj[u ^ 1][0].push_back(v);
	adj[v ^ 1][0].push_back(u);
	adj[u][1].push_back(v ^ 1);
	adj[v][1].push_back(u ^ 1);
}

void dfs_t(int u) {
	mark[u] = 1;
	for (auto v: adj[u][0])
		if (!mark[v])
			dfs_t(v);
	topol.push_back(u);
}

void dfs_c(int u) {
	mark[u] = c;
	for (auto v: adj[u][1])
		if (!mark[v])
			dfs_c(v);
}

bool can() {
	topol.clear();
	memset(mark, 0, sizeof mark);
	for (int u = c = 0; u < 2 * n; u++)
		if (!mark[u])
			dfs_t(u);
	reverse(topol.begin(), topol.end());
	memset(mark, 0, sizeof mark);
	for (auto u: topol)
		if (!mark[u]) {
			c++;
			dfs_c(u);
		}

	for (int u = 0; u < n; u++)
		if (mark[u << 1] == mark[u << 1 ^ 1])
			return false;
	return true;
}

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = l - 1; ~i; i--) {
		nxt[i][0] = x[0];
		nxt[i][1] = x[1];
		a[i] = (s[i] == 'V');
		if (!~x[0] || a[x[0]] != a[i])
			x[1] = x[0];
		x[0] = i;
	}

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		char c1, c2;
		cin >> u >> c1 >> v >> c2;
		add_clause((--u <<= 1) ^= (c1 != 'V'), (--v <<= 1) ^= (c2 == 'V'));
	}
	cin >> s;
	for (int i = 0; i < n; i++) {
		b[i] = s[i] - 'a';
		add_clause(i << 1 ^ a[b[i]], i << 1 ^ a[b[i]]);
	}
	if (!~x[1])
		for (int i = 0; i < n; i++)
			add_clause(i << 1 ^ a[0], i << 1 ^ a[0]);
}

void solve() {
	if (can()) {
		cout << s << endl;
		return;
	}
	for (int i = n - 1; ~i; i--) {
		for (int k = 0; k < 2; k++) {
			adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
			adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
		}
		for (int j = 0; j < 2; j++)
			if (~nxt[b[i]][j]) {
				add_clause(i << 1 ^ j, i << 1 ^ j);
				if (can()) {
					s[i] = 'a' + nxt[b[i]][j];
					for (int p = i + 1; p < n; p++) {
						add_clause(p << 1 ^ a[0], p << 1 ^ a[0]);
						if (can()) {
							s[p] = 'a';
							continue;
						}
						s[p] = 'a' + x[1];
						for (int k = 0; k < 2; k++) {
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
						}
					}
					cout << s << endl;
					return;
				}
				for (int k = 0; k < 2; k++) {
					adj[i << 1 ^ j ^ k][!k].pop_back();
					adj[i << 1 ^ j ^ k][!k].pop_back();
				}
			}
	}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 200 + 5, M = 4 * N * N;
int n, m, l, c, a[N], p1[M], p2[M], mark[2 * N];
char x[2] = {'*', '*'}, y[2] = {'*', '*'};
bool a0[26 + 4], a1[M], a2[M], a3[N];
vector<int> adj[2 * N][2], topol;
string s, s1[M], s2[M];

void add_clause(int u, int v) {
	adj[u ^ 1][0].push_back(v);
	adj[v ^ 1][0].push_back(u);
	adj[u][1].push_back(v ^ 1);
	adj[v][1].push_back(u ^ 1);
}

void dfs_t(int u) {
	mark[u] = 1;
	for (auto v: adj[u][0])
		if (!mark[v])
			dfs_t(v);
	topol.push_back(u);
}

void dfs_c(int u) {
	mark[u] = c;
	for (auto v: adj[u][1])
		if (!mark[v])
			dfs_c(v);
}

bool check(int p) {
	topol.clear();
	for (int u = c = 0; u < 2 * n; u++) {
		adj[u][0].clear();
		adj[u][1].clear();
	}
	for (int u = 0; u < p; u++) {
		s[u] = 'a' + a[u];
		add_clause(u << 1 ^ !a0[a[u]], u << 1 ^ !a0[a[u]]);
	}
	if (p < n)
		for (int i = 0; i < 2; i++)
			if (y[i] <= a[p] + 'a')
				add_clause(p << 1 ^ i, p << 1 ^ i);
	for (int i = 0; i < m; i++)
		add_clause(p1[i] << 1 ^ a1[i], p2[i] << 1 ^ !a2[i]);
	memset(mark, 0, sizeof mark);
	for (int u = 0; u < 2 * n; u++)
		if (!mark[u])
			dfs_t(u);
	reverse(topol.begin(), topol.end());
	memset(mark, 0, sizeof mark);
	for (auto u: topol)
		if (!mark[u]) {
			c++;
			dfs_c(u);
		}
	for (int u = 0; u < n; u++) {
		if (mark[u << 1] == mark[u << 1 ^ 1])
			return false;
		a3[u] = (mark[u << 1] > mark[u << 1 ^ 1]);
	}
	for (int i = p + 1; i < n; i++)
		s[i] = x[a3[i]];
	if (p == n)
		return true;
	for (int i = a[p] + 1; i < l; i++)
		if (a0[i] == a3[p]) {
			s[p] = 'a' + i;
			return true;
		}
	return false;
}

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = 0; i < l; i++)
		y[a0[i] = (s[i] == 'V')] = 'a' + i;
	for (int i = l - 1; ~i; i--)
		x[a0[i]] = 'a' + i;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		char c1, c2;
		cin >> p1[i] >> c1 >> p2[i] >> c2;

		p1[i]--;
		p2[i]--;
		a1[i] = (c1 == 'V');
		a2[i] = (c2 == 'V');
	}
	for (int i = 0; i < n; i++) {
		char c;
		cin >> c;
		a[i] = c - 'a';
	}
	s.resize(n);
}

void solve() {
	for (int i = n; ~i; i--)
		if (check(i)) {
			cout << s << endl;
			return;
		}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 400 + 5, M = N * N, K = 26 + 4;
int l, n, m, c, mark[N], a[K], b[N], nxt[K][2], x[2] = {-1, -1};
vector<int> adj[N][2], topol;
string s;

void add_clause(int u, int v) {
	adj[u ^ 1][0].push_back(v);
	adj[v ^ 1][0].push_back(u);
	adj[u][1].push_back(v ^ 1);
	adj[v][1].push_back(u ^ 1);
}

void dfs_t(int u) {
	mark[u] = 1;
	for (auto v: adj[u][0])
		if (!mark[v])
			dfs_t(v);
	topol.push_back(u);
}

void dfs_c(int u) {
	mark[u] = c;
	for (auto v: adj[u][1])
		if (!mark[v])
			dfs_c(v);
}

bool can() {
	topol.clear();
	memset(mark, 0, sizeof mark);
	for (int u = c = 0; u < 2 * n; u++)
		if (!mark[u])
			dfs_t(u);
	reverse(topol.begin(), topol.end());
	memset(mark, 0, sizeof mark);
	for (auto u: topol)
		if (!mark[u]) {
			c++;
			dfs_c(u);
		}

	for (int u = 0; u < n; u++)
		if (mark[u << 1] == mark[u << 1 ^ 1])
			return false;
	return true;
}

void readInput() {
	cin >> s;
	l = s.size();
	for (int i = l - 1; ~i; i--) {
		nxt[i][0] = x[0];
		nxt[i][1] = x[1];
		a[i] = (s[i] == 'V');
		if (~x[0] && a[x[0]] != a[i])
			x[1] = x[0];
		x[0] = i;
	}

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		char c1, c2;
		cin >> u >> c1 >> v >> c2;
		add_clause(--u << 1 ^ (c1 != 'V'), --v << 1 ^ (c2 == 'V'));
	}
	if (!~x[1])
		for (int i = 0; i < n; i++)
			add_clause(i << 1 ^ a[0], i << 1 ^ a[0]);
	cin >> s;
	for (int i = 0; i < n; i++) {
		b[i] = s[i] - 'a';
		add_clause(i << 1 ^ a[b[i]], i << 1 ^ a[b[i]]);
	}
}

void solve() {
	if (can()) {
		cout << s << endl;
		return;
	}
	for (int i = n - 1; ~i; i--) {
		for (int k = 0; k < 2; k++) {
			adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
			adj[i << 1 ^ a[b[i]] ^ k][!k].pop_back();
		}
		for (int j = 0; j < 2; j++)
			if (~nxt[b[i]][j]) {
				add_clause(i << 1 ^ a[nxt[b[i]][j]], i << 1 ^ a[nxt[b[i]][j]]);
				if (can()) {
					s[i] = 'a' + nxt[b[i]][j];
					for (int p = i + 1; p < n; p++) {
						add_clause(p << 1 ^ a[0], p << 1 ^ a[0]);
						if (can()) {
							s[p] = 'a';
							continue;
						}
						s[p] = 'a' + x[1];
						for (int k = 0; k < 2; k++) {
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
							adj[p << 1 ^ a[0] ^ k][!k].pop_back();
						}
					}
					cout << s << endl;
					return;
				}
				for (int k = 0; k < 2; k++) {
					adj[i << 1 ^ a[nxt[b[i]][j]] ^ k][!k].pop_back();
					adj[i << 1 ^ a[nxt[b[i]][j]] ^ k][!k].pop_back();
				}
			}
	}
	cout << "-1\n";
}

int main() {
	ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

int n, m, len, sta;
bool find, mp[405][405];
char table[30], s[205], ans[205];

int inv(const int &t) { return t < n ? t + n : t - n; }

int get(const char &c) { return c == 'V' ? 1 : 2; }

void print(int t, bool any) {
  if (t == n) return void((find = true, puts(ans)));
  for (char i = any ? 'a' : s[t]; i < 'a' + len; ++ i) {
    ans[t] = i;
    for (int j = 0, n1, n2; j < t; ++ j) {
      n1 = j + (get(table[ans[j] - 'a']) - 1) * n, n2 = t + (get(table[ans[t] - 'a']) - 1) * n;
      if (mp[n1][inv(n2)] || mp[n2][inv(n1)]) goto illegal;
    }
    print(t + 1, any || i > s[t]);
    if (find) return; illegal: ;
  }
}

int main() {
  scanf("%s%d%d", table, &n, &m), len = strlen(table);
  for (int i = 0; i < len; ++ i) sta |= get(table[i]);
  if (sta < 3)
    for (int i = 0; i < n; ++ i) { if (sta == 1) mp[inv(i)][i] = 1; else mp[i][inv(i)] = 1; }
  for (int i = 0; i < m; ++ i) {
    int p1, p2; char t1, t2; scanf("%d %c%d %c", &p1, &t1, &p2, &t2), -- p1, -- p2;
    if (t1 == 'C') p1 = inv(p1); if (t2 == 'C') p2 = inv(p2);
    mp[p1][p2] = mp[inv(p2)][inv(p1)] = 1;
  }
  scanf("%s", s);
  for (int k = 0; k < n << 1; ++ k)
    for (int i = 0; i < n << 1; ++ i)
      for (int j = 0; j < n << i; ++ j) mp[i][j] |= mp[i][k] && mp[k][j];
  for (int i = 0; i < n << 1; ++ i) if (mp[i][inv(i)] && mp[inv(i)][i]) return puts("-1"), 0;
  return print(0, 0), ! find && puts("-1"), 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

int n, m, len, sta;
bool find, mp[405][405];
char table[30], s[205], ans[205];

int inv(const int &t) { return t < n ? t + n : t - n; }

int get(const char &c) { return c == 'V' ? 1 : 2; }

void print(int t, bool any) {
  if (t == n) return void((find = true, puts(ans)));
  for (char i = any ? 'a' : s[t]; i < 'a' + len; ++ i) {
    ans[t] = i;
    for (int j = 0, n1, n2; j < t; ++ j) {
      n1 = j + (get(table[ans[j] - 'a']) - 1) * n, n2 = t + (get(table[ans[t] - 'a']) - 1) * n;
      if (mp[n1][inv(n2)] || mp[n2][inv(n1)]) goto illegal;
    }
    print(t + 1, any || i > s[t]);
    if (find) return; illegal: ;
  }
}

int main() {
  scanf("%s%d%d", table, &n, &m), len = strlen(table);
  for (int i = 0; i < len; ++ i) sta |= get(table[i]);
  if (sta < 3)
    for (int i = 0; i < n; ++ i) { if (sta == 1) mp[inv(i)][i] = 1; else mp[i][inv(i)] = 1; }
  for (int i = 0; i < m; ++ i) {
    int p1, p2; char t1, t2; scanf("%d %c%d %c", &p1, &t1, &p2, &t2), -- p1, -- p2;
    if (t1 == 'C') p1 = inv(p1); if (t2 == 'C') p2 = inv(p2);
    mp[p1][p2] = mp[inv(p2)][inv(p1)] = 1;
  }
  scanf("%s", s);
  for (int k = 0; k < n << 1; ++ k)
    for (int i = 0; i < n << 1; ++ i)
      for (int j = 0; j < n << 1; ++ j) mp[i][j] |= mp[i][k] && mp[k][j];
  for (int i = 0; i < n << 1; ++ i) if (mp[i][inv(i)] && mp[inv(i)][i]) return puts("-1"), 0;
  return print(0, 0), ! find && puts("-1"), 0;
}


#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
string s,inp;
ll n,m,nx[27][2],a[405],b[405];
vll g[405],gc[405];
bool pos;

void color(ll st){
    b[st]=1;
    if(st <= n) b[st+n]=0;
    else b[st-n]=0;
    for(ll v:g[st]) {
        if(b[v] == -1) color(v);
        else if(b[v] == 0) pos=0;
    }
}
void colora(ll st){
    a[st]=1;
    if(st <= n) a[st+n]=0;
    else a[st-n]=0;
    for(ll v:g[st]) {
        if(a[v] == -1) colora(v);
        else if(a[v] == 0) pos=0;
    }
}
vll path;
ll cmpno,cmp[405],mark[405];
void dfs(ll st){
    mark[st]=1;
    for(ll v:g[st]) if(b[v] == -1 && !mark[v]) dfs(v);
    path.pb(st);
}
void dfsc(ll st){
    cmp[st]=cmpno;
    for(ll v:gc[st]) if(b[v] == -1 && cmp[v] == -1) dfsc(v);
}
void check(ll st){
    if(st > n ) return;
    path.clear();
    rep(i,1,2*n ) mark[i]=0;

    rep(i,st,2*n) if(!mark[i] && b[i] == -1) dfs(i);
    reverse(path.begin(),path.end());

    rep(i,1,2*n) cmp[i]=-1;
    cmpno = 0;
    for(ll v:path){
        if(cmp[v] != -1) continue;
        if(b[v] != -1) continue;
        ++cmpno;
        dfsc(v);
    }
    for(ll v:path){
        if(v <= n && cmp[v] == cmp[v+n]) pos=0;
        if(v > n && cmp[v] == cmp[v-n]) pos=0;
    }
}
string change(string inp){
    string ret;
    rep(i,1,n) ret+=inp[i];
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    ll k = s.size();
    s="$"+s;
    nx[k][0]=nx[k][1]=k+5;
    rev(i,k-1,1){
        if(s[i+1] == 'V') nx[i][1]=i+1,nx[i][0]=nx[i+1][0];
        else nx[i][0]=i+1,nx[i][1]=nx[i+1][1];
    }
    ll tc=0;
    rep(i,1,k) if(s[i] == 'V') tc++;

    cin>>n>>m;
    rep(i,1,m){
        ll p1,p2;char v1,v2;
        cin>>p1>>v1>>p2>>v2;
        if(v1 == 'V' && v2 == 'V'){
            g[p1+n].pb(p2+n);
            g[p2].pb(p1);

            gc[p2+n].pb(p1+n);
            gc[p1].pb(p2);
        }
        else if(v1 == 'V'){
            g[p1+n].pb(p2);
            g[p2+n].pb(p1);

            gc[p2].pb(p1+n);
            gc[p1].pb(p2+n);
        }
        else if(v2 == 'V'){
            g[p1].pb(p2+n);
            g[p2].pb(p1+n);

            gc[p2+n].pb(p1);
            gc[p1+n].pb(p2);
        }
        else{
            g[p1].pb(p2);
            g[p2+n].pb(p1+n);

            gc[p2].pb(p1);
            gc[p1+n].pb(p2+n);
        }
    }
    cin>>inp;inp="$"+inp;

    if(!tc || tc == k){
        if(!tc) rep(i,1,n) a[i]=1;
        else rep(i,n+1,2*n) a[i]=1;
        bool notpos=0;
        rep(i,1,2*n) if(a[i]){
            for(ll v:g[i]) if(!a[v]) notpos=1;
        }
        if(notpos ) cout<<-1<<'\n';
        else cout<<change(inp)<<'\n';
        return 0;
    }

    rep(i,1,2*n) a[i]=-1;
    ll ch = 0,who=-1;

    pos=1;
    rep(i,1,n){
        rep(j,1,2*n) b[j]=a[j];

        ll ps=inp[i]-'a'+1;
        bool is0=0;
        if(nx[ps][0] <= k){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    who=0;ch=i;is0=1;
                }
            }
        }
        if(nx[ps][1] <= k){
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    ch=i;
                    if(!is0) who=1;
                    else if(nx[ps][1] < nx[ps][0]) who=1;
                }
            }
        }
        pos=1;
        if(s[ps] == 'V'){
            colora(i+n);
            if(!pos) break;
        }
        else{
            colora(i);
            if(!pos) break;
        }
    }
    if(pos) {
        cout<<change(inp)<<'\n';
        return 0;
    }
    if(!ch){
        cout<<-1<<'\n';
        return 0;
    }
    cerr<<ch<<" "<<who<<" "<<inp[ch]<<endl;
    rep(i,1,2*n) a[i]=-1;
    rep(i,1,ch-1){
        ll ps=inp[i]-'a'+1;
        if(s[ps] == 'V') colora(i+n);
        else colora(i);
    }

    ll ps=inp[ch]-'a'+1;
    if(who) colora(ch+n);
    else colora(ch);
    inp[ch]='a'+nx[ps][who]-1;

    if(ch == n){
        cout<<change(inp)<<'\n';
        return 0;
    }

    char cf,ctr;
    if(s[1] == 'V') ctr='a',cf='a'+nx[1][0]-1;
    else cf='a',ctr='a'+nx[1][1]-1;

    ch++;
    rep(i,ch,n){
        rep(j,1,2*n) b[j]=a[j];
        if(cf == 'a'){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i);
                }
                else{
                    inp[i]=ctr;
                    colora(i+n);
                }
            }
            else{
                inp[i]=ctr;
                colora(i+n);
            }
        }
        else{
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i+n);
                }
                else{
                    inp[i]=cf;
                    colora(i);
                }
            }
            else{
                inp[i]=cf;
                colora(i);
            }
        }
    }
    cout<<change(inp)<<'\n';
}


#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
string s,inp;
ll n,m,nx[27][2],a[405],b[405];
vll g[405],gc[405];
bool pos;

void color(ll st){
    b[st]=1;
    if(st <= n) b[st+n]=0;
    else b[st-n]=0;
    for(ll v:g[st]) {
        if(b[v] == -1) color(v);
        else if(b[v] == 0) pos=0;
    }
}
void colora(ll st){
    a[st]=1;
    if(st <= n) a[st+n]=0;
    else a[st-n]=0;
    for(ll v:g[st]) {
        if(a[v] == -1) colora(v);
        else if(a[v] == 0) pos=0;
    }
}
vll path;
ll cmpno,cmp[405],mark[405];
void dfs(ll st){
    mark[st]=1;
    for(ll v:g[st]) if(b[v] == -1 && !mark[v]) dfs(v);
    path.pb(st);
}
void dfsc(ll st){
    cmp[st]=cmpno;
    for(ll v:gc[st]) if(b[v] == -1 && cmp[v] == -1) dfsc(v);
}
void check(ll st){
    if(st > n ) return;
    path.clear();
    rep(i,1,2*n ) mark[i]=0;

    rep(i,st,2*n) if(!mark[i] && b[i] == -1) dfs(i);
    reverse(path.begin(),path.end());

    rep(i,1,2*n) cmp[i]=-1;
    cmpno = 0;
    for(ll v:path){
        if(cmp[v] != -1) continue;
        if(b[v] != -1) continue;
        ++cmpno;
        dfsc(v);
    }
    for(ll v:path){
        if(v <= n && cmp[v] == cmp[v+n]) pos=0;
        if(v > n && cmp[v] == cmp[v-n]) pos=0;
    }
}
string change(string inp){
    string ret;
    rep(i,1,n) ret+=inp[i];
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    ll k = s.size();
    s="$"+s;
    nx[k][0]=nx[k][1]=k+5;
    rev(i,k-1,1){
        if(s[i+1] == 'V') nx[i][1]=i+1,nx[i][0]=nx[i+1][0];
        else nx[i][0]=i+1,nx[i][1]=nx[i+1][1];
    }
    ll tc=0;
    rep(i,1,k) if(s[i] == 'V') tc++;

    cin>>n>>m;
    rep(i,1,m){
        ll p1,p2;char v1,v2;
        cin>>p1>>v1>>p2>>v2;
        if(v1 == 'V' && v2 == 'V'){
            g[p1+n].pb(p2+n);
            g[p2].pb(p1);

            gc[p2+n].pb(p1+n);
            gc[p1].pb(p2);
        }
        else if(v1 == 'V'){
            g[p1+n].pb(p2);
            g[p2+n].pb(p1);

            gc[p2].pb(p1+n);
            gc[p1].pb(p2+n);
        }
        else if(v2 == 'V'){
            g[p1].pb(p2+n);
            g[p2].pb(p1+n);

            gc[p2+n].pb(p1);
            gc[p1+n].pb(p2);
        }
        else{
            g[p1].pb(p2);
            g[p2+n].pb(p1+n);

            gc[p2].pb(p1);
            gc[p1+n].pb(p2+n);
        }
    }
    cin>>inp;inp="$"+inp;

    if(!tc || tc == k){
        if(!tc) rep(i,1,n) a[i]=1;
        else rep(i,n+1,2*n) a[i]=1;
        bool notpos=0;
        rep(i,1,2*n) if(a[i]){
            for(ll v:g[i]) if(!a[v]) notpos=1;
        }
        if(notpos ) cout<<-1<<'\n';
        else cout<<change(inp)<<'\n';
        return 0;
    }

    rep(i,1,2*n) a[i]=-1;
    ll ch = 0,who=-1;

    pos=1;
    rep(i,1,n){
        rep(j,1,2*n) b[j]=a[j];

        ll ps=inp[i]-'a'+1;
        bool is0=0;
        if(nx[ps][0] <= k){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    who=0;ch=i;is0=1;
                }
            }
        }
        if(nx[ps][1] <= k){
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    ch=i;
                    if(!is0) who=1;
                    else if(nx[ps][1] < nx[ps][0]) who=1;
                }
            }
        }
        pos=1;
        if(s[ps] == 'V'){
            colora(i+n);
            if(!pos) break;
        }
        else{
            colora(i);
            if(!pos) break;
        }
    }
    if(pos) {
        cout<<change(inp)<<'\n';
        return 0;
    }
    if(!ch){
        cout<<-1<<'\n';
        return 0;

    }
    if(s == "VVVVVVVVVVVVVVVVCCCCCCCCCC" && n == 200 && m == 2000)
        cout<<ch<<" "<<who<<" "<<inp[ch]<<'\n';
    rep(i,1,2*n) a[i]=-1;
    rep(i,1,ch-1){
        ll ps=inp[i]-'a'+1;
        if(s[ps] == 'V') colora(i+n);
        else colora(i);
    }

    ll ps=inp[ch]-'a'+1;
    if(who) colora(ch+n);
    else colora(ch);
    inp[ch]='a'+nx[ps][who]-1;

    if(ch == n){
        cout<<change(inp)<<'\n';
        return 0;
    }

    char cf,ctr;
    if(s[1] == 'V') ctr='a',cf='a'+nx[1][0]-1;
    else cf='a',ctr='a'+nx[1][1]-1;

    ch++;
    rep(i,ch,n){
        rep(j,1,2*n) b[j]=a[j];
        if(cf == 'a'){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i);
                }
                else{
                    inp[i]=ctr;
                    colora(i+n);
                }
            }
            else{
                inp[i]=ctr;
                colora(i+n);
            }
        }
        else{
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i+n);
                }
                else{
                    inp[i]=cf;
                    colora(i);
                }
            }
            else{
                inp[i]=cf;
                colora(i);
            }
        }
    }
    cout<<change(inp)<<'\n';
}


#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
string s,inp;
ll n,m,nx[27][2],a[405],b[405];
vll g[405],gc[405];
bool pos;

void color(ll st){
    b[st]=1;
    if(st <= n) b[st+n]=0;
    else b[st-n]=0;
    for(ll v:g[st]) {
        if(b[v] == -1) color(v);
        else if(b[v] == 0) pos=0;
    }
}
void colora(ll st){
    a[st]=1;
    if(st <= n) a[st+n]=0;
    else a[st-n]=0;
    for(ll v:g[st]) {
        if(a[v] == -1) colora(v);
        else if(a[v] == 0) pos=0;
    }
}
vll path;
ll cmpno,cmp[405],mark[405];
void dfs(ll st){
    mark[st]=1;
    for(ll v:g[st]) if(b[v] == -1 && !mark[v]) dfs(v);
    path.pb(st);
}
void dfsc(ll st){
    cmp[st]=cmpno;
    for(ll v:gc[st]) if(b[v] == -1 && cmp[v] == -1) dfsc(v);
}
void check(ll st){
    if(st > n ) return;
    path.clear();
    rep(i,1,2*n ) mark[i]=0;

    rep(i,st,2*n) if(!mark[i] && b[i] == -1) dfs(i);
    reverse(path.begin(),path.end());

    rep(i,1,2*n) cmp[i]=-1;
    cmpno = 0;
    for(ll v:path){
        if(cmp[v] != -1) continue;
        if(b[v] != -1) continue;
        ++cmpno;
        dfsc(v);
    }
    for(ll v:path){
        if(v <= n && cmp[v] == cmp[v+n]) pos=0;
        if(v > n && cmp[v] == cmp[v-n]) pos=0;
    }
}
string change(string inp){
    string ret;
    rep(i,1,n) ret+=inp[i];
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    ll k = s.size();
    s="$"+s;
    nx[k][0]=nx[k][1]=k+5;
    rev(i,k-1,1){
        if(s[i+1] == 'V') nx[i][1]=i+1,nx[i][0]=nx[i+1][0];
        else nx[i][0]=i+1,nx[i][1]=nx[i+1][1];
    }
    ll tc=0;
    rep(i,1,k) if(s[i] == 'V') tc++;

    cin>>n>>m;
    rep(i,1,m){
        ll p1,p2;char v1,v2;
        cin>>p1>>v1>>p2>>v2;
        if(v1 == 'V' && v2 == 'V'){
            g[p1+n].pb(p2+n);
            g[p2].pb(p1);

            gc[p2+n].pb(p1+n);
            gc[p1].pb(p2);
        }
        else if(v1 == 'V'){
            g[p1+n].pb(p2);
            g[p2+n].pb(p1);

            gc[p2].pb(p1+n);
            gc[p1].pb(p2+n);
        }
        else if(v2 == 'V'){
            g[p1].pb(p2+n);
            g[p2].pb(p1+n);

            gc[p2+n].pb(p1);
            gc[p1+n].pb(p2);
        }
        else{
            g[p1].pb(p2);
            g[p2+n].pb(p1+n);

            gc[p2].pb(p1);
            gc[p1+n].pb(p2+n);
        }
    }
    cin>>inp;inp="$"+inp;

    if(!tc || tc == k){
        if(!tc) rep(i,1,n) a[i]=1;
        else rep(i,n+1,2*n) a[i]=1;
        bool notpos=0;
        rep(i,1,2*n) if(a[i]){
            for(ll v:g[i]) if(!a[v]) notpos=1;
        }
        if(notpos ) cout<<-1<<'\n';
        else cout<<change(inp)<<'\n';
        return 0;
    }

    rep(i,1,2*n) a[i]=-1;
    ll ch = 0,who=-1;

    pos=1;
    rep(i,1,n){
        rep(j,1,2*n) b[j]=a[j];

        ll ps=inp[i]-'a'+1;
        bool is0=0;
        if(nx[ps][0] <= k){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    who=0;ch=i;is0=1;
                }
            }
        }
        if(nx[ps][1] <= k){
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    ch=i;
                    if(!is0) who=1;
                    else if(nx[ps][1] < nx[ps][0]) who=1;
                }
            }
        }
        pos=1;
        if(s[ps] == 'V'){
            colora(i+n);
            if(!pos) break;
        }
        else{
            colora(i);
            if(!pos) break;
        }
    }
    if(pos) {
        cout<<change(inp)<<'\n';
        return 0;
    }
    if(!ch){
        cout<<-1<<'\n';
        return 0;
    }
    rep(i,1,2*n) a[i]=-1;
    rep(i,1,ch-1){
        ll ps=inp[i]-'a'+1;
        if(s[ps] == 'V') colora(i+n);
        else colora(i);
    }

    ll ps=inp[ch]-'a'+1;
    if(who) colora(ch+n);
    else colora(ch);
    inp[ch]='a'+nx[ps][who]-1;

    if(ch == n){
        cout<<change(inp)<<'\n';
        return 0;
    }

    char cf,ctr;
    if(s[1] == 'V') ctr='a',cf='a'+nx[1][0]-1;
    else cf='a',ctr='a'+nx[1][1]-1;

    ch++;
    rep(i,ch,n){
        rep(j,1,2*n) b[j]=a[j];
        if(cf == 'a'){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i);
                }
                else{
                    inp[i]=ctr;
                    colora(i+n);
                }
            }
            else{
                inp[i]=ctr;
                colora(i+n);
            }
        }
        else{
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i+n);
                }
                else{
                    inp[i]=cf;
                    colora(i);
                }
            }
            else{
                inp[i]=cf;
                colora(i);
            }
        }
    }
    cout<<change(inp)<<'\n';
}


#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
string s,inp;
ll n,m,nx[27][2],a[405],b[405];
vll g[405],gc[405];
bool pos;

void color(ll st){
    b[st]=1;
    if(st <= n) b[st+n]=0;
    else b[st-n]=0;
    for(ll v:g[st]) {
        if(b[v] == -1) color(v);
        else if(b[v] == 0) pos=0;
    }
}
void colora(ll st){
    a[st]=1;
    if(st <= n) a[st+n]=0;
    else a[st-n]=0;
    for(ll v:g[st]) {
        if(a[v] == -1) colora(v);
        else if(a[v] == 0) pos=0;
    }
}
vll path;
ll cmpno,cmp[405],mark[405];
void dfs(ll st){
    mark[st]=1;
    for(ll v:g[st]) if(b[v] == -1 && !mark[v]) dfs(v);
    path.pb(st);
}
void dfsc(ll st){
    cmp[st]=cmpno;
    for(ll v:gc[st]) if(cmp[v] == -1) dfsc(v);
}
void check(ll st){
    if(st > n )return;
    path.clear();
    rep(i,1,2*n ) mark[i]=0;

    rep(i,st,2*n) if(!mark[st] && b[st] == -1) dfs(st);
    reverse(path.begin(),path.end());

    rep(i,1,2*n) cmp[i]=-1;
    cmpno = 0;
    for(ll v:path){
        if(cmp[v] != -1) continue;
        ++cmpno;
        dfsc(v);
    }
    for(ll v:path){
        if(v <= n && cmp[v] == cmp[v+n]) pos=0;
        if(v > n && cmp[v] == cmp[v-n]) pos=0;
    }
}
string change(string inp){
    string ret;
    rep(i,1,n) ret+=inp[i];
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    ll k = s.size();
    s="$"+s;
    nx[k][0]=nx[k][1]=k+5;
    rev(i,k-1,1){
        if(s[i+1] == 'V') nx[i][1]=i+1,nx[i][0]=nx[i+1][0];
        else nx[i][0]=i+1,nx[i][1]=nx[i+1][1];
    }
    ll tc=0;
    rep(i,1,k) if(s[i] == 'V') tc++;

    cin>>n>>m;
    rep(i,1,m){
        ll p1,p2;char v1,v2;
        cin>>p1>>v1>>p2>>v2;
        if(v1 == 'V' && v2 == 'V'){
            g[p1+n].pb(p2+n);
            g[p2].pb(p1);

            gc[p2+n].pb(p1+n);
            gc[p1].pb(p2);
        }
        else if(v1 == 'V'){
            g[p1+n].pb(p2);
            g[p2+n].pb(p1);

            gc[p2].pb(p1+n);
            gc[p1].pb(p2+n);
        }
        else if(v2 == 'V'){
            g[p1].pb(p2+n);
            g[p2].pb(p1+n);

            gc[p2+n].pb(p1);
            gc[p1+n].pb(p2);
        }
        else{
            g[p1].pb(p2);
            g[p2+n].pb(p1+n);

            gc[p2].pb(p1);
            gc[p1+n].pb(p2+n);
        }
    }
    cin>>inp;inp="$"+inp;

    if(!tc || tc == k){
        if(!tc) rep(i,1,n) a[i]=1;
        else rep(i,n+1,2*n) a[i]=1;
        bool notpos=0;
        rep(i,1,2*n) if(a[i]){
            for(ll v:g[i]) if(!a[v]) notpos=1;
        }
        if(notpos ) cout<<-1<<'\n';
        else cout<<change(inp)<<'\n';
        return 0;
    }

    rep(i,1,2*n) a[i]=-1;
    ll ch = 0,who=-1;

    pos=1;
    rep(i,1,n){
        rep(j,1,2*n) b[j]=a[j];

        ll ps=inp[i]-'a'+1;
        bool is0=0;
        if(nx[ps][0] <= k){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    who=0;ch=i;is0=1;
                }
            }
        }
        if(nx[ps][1] <= k){
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    ch=i;
                    if(!is0) who=1;
                    else if(nx[ps][1] < nx[ps][0]) who=1;
                }
            }
        }
        pos=1;
        if(s[ps] == 'V'){
            colora(i+n);
            if(!pos) break;
        }
        else{
            colora(i);
            if(!pos) break;
        }
    }
    if(pos) {
        cout<<change(inp)<<'\n';
        return 0;
    }
    if(!ch){
        cout<<-1<<'\n';
        return 0;
    }
    rep(i,1,2*n) a[i]=-1;
    rep(i,1,ch-1){
        ll ps=inp[i]-'a'+1;
        if(s[ps] == 'V') colora(i+n);
        else colora(i);
    }

    ll ps=inp[ch]-'a'+1;
    if(who) colora(ch+n);
    else colora(ch);
    inp[ch]='a'+nx[ps][who]-1;

    if(ch == n){
        cout<<change(inp)<<'\n';
        return 0;
    }

    char cf,ctr;
    if(s[1] == 'V') ctr='a',cf='a'+nx[1][0]-1;
    else cf='a',ctr='a'+nx[1][1]-1;

    ch++;
    rep(i,ch,n){
        rep(j,1,2*n) b[j]=a[j];
        if(cf == 'a'){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i);
                }
                else{
                    inp[i]=ctr;
                    colora(i+n);
                }
            }
            else{
                inp[i]=ctr;
                colora(i+n);
            }
        }
        else{
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i+n);
                }
                else{
                    inp[i]=cf;
                    colora(i);
                }
            }
            else{
                inp[i]=cf;
                colora(i);
            }
        }
    }
    cout<<change(inp)<<'\n';
}


#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
string s,inp;
ll n,m,nx[27][2],a[405],b[405];
vll g[405],gc[405];
bool pos;

void color(ll st){
    b[st]=1;
    if(st <= n) b[st+n]=0;
    else b[st-n]=0;
    for(ll v:g[st]) {
        if(b[v] == -1) color(v);
        else if(b[v] == 0) pos=0;
    }
}
void colora(ll st){
    a[st]=1;
    if(st <= n) a[st+n]=0;
    else a[st-n]=0;
    for(ll v:g[st]) {
        if(a[v] == -1) colora(v);
        else if(a[v] == 0) pos=0;
    }
}
vll path;
ll cmpno,cmp[405],mark[405];
void dfs(ll st){
    mark[st]=1;
    for(ll v:g[st]) if(b[v] == -1 && !mark[v]) dfs(v);
    path.pb(st);
}
void dfsc(ll st){
    cmp[st]=cmpno;
    for(ll v:gc[st]) if(b[v] == -1 && cmp[v] == -1) dfsc(v);
}
void check(ll st){
    if(st > n ) return;
    path.clear();
    rep(i,1,2*n ) mark[i]=0;

    rep(i,st,2*n) if(!mark[i] && b[i] == -1) dfs(i);
    reverse(path.begin(),path.end());

    rep(i,1,2*n) cmp[i]=-1;
    cmpno = 0;
    for(ll v:path){
        if(cmp[v] != -1) continue;
        if(b[v] != -1) continue;
        ++cmpno;
        dfsc(v);
    }
    for(ll v:path){
        if(v <= n && cmp[v] == cmp[v+n]) pos=0;
        if(v > n && cmp[v] == cmp[v-n]) pos=0;
    }
}
string change(string inp){
    string ret;
    rep(i,1,n) ret+=inp[i];
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    ll k = s.size();
    s="$"+s;
    nx[k][0]=nx[k][1]=k+5;
    rev(i,k-1,1){
        if(s[i+1] == 'V') nx[i][1]=i+1,nx[i][0]=nx[i+1][0];
        else nx[i][0]=i+1,nx[i][1]=nx[i+1][1];
    }
    ll tc=0;
    rep(i,1,k) if(s[i] == 'V') tc++;

    cin>>n>>m;
    rep(i,1,m){
        ll p1,p2;char v1,v2;
        cin>>p1>>v1>>p2>>v2;
        if(v1 == 'V' && v2 == 'V'){
            g[p1+n].pb(p2+n);
            g[p2].pb(p1);

            gc[p2+n].pb(p1+n);
            gc[p1].pb(p2);
        }
        else if(v1 == 'V'){
            g[p1+n].pb(p2);
            g[p2+n].pb(p1);

            gc[p2].pb(p1+n);
            gc[p1].pb(p2+n);
        }
        else if(v2 == 'V'){
            g[p1].pb(p2+n);
            g[p2].pb(p1+n);

            gc[p2+n].pb(p1);
            gc[p1+n].pb(p2);
        }
        else{
            g[p1].pb(p2);
            g[p2+n].pb(p1+n);

            gc[p2].pb(p1);
            gc[p1+n].pb(p2+n);
        }
    }
    cin>>inp;inp="$"+inp;

    if(!tc || tc == k){
        if(!tc) rep(i,1,n) a[i]=1;
        else rep(i,n+1,2*n) a[i]=1;
        bool notpos=0;
        rep(i,1,2*n) if(a[i]){
            for(ll v:g[i]) if(!a[v]) notpos=1;
        }
        if(notpos ) cout<<-1<<'\n';
        else cout<<change(inp)<<'\n';
        return 0;
    }

    rep(i,1,2*n) a[i]=-1;
    ll ch = 0,who=-1;

    pos=1;
    rep(i,1,n){
        rep(j,1,2*n) b[j]=a[j];

        ll ps=inp[i]-'a'+1;
        bool is0=0;
        if(nx[ps][0] <= k){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    who=0;ch=i;is0=1;
                }
            }
        }
        if(nx[ps][1] <= k){
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    ch=i;
                    if(!is0) who=1;
                    else if(nx[ps][1] < nx[ps][0]) who=1;
                }
            }
        }
        pos=1;
        if(s[ps] == 'V'){
            colora(i+n);
            if(!pos) break;
        }
        else{
            colora(i);
            if(!pos) break;
        }
    }
    if(pos) {
        cout<<change(inp)<<'\n';
        return 0;
    }
    if(!ch){
        cout<<-1<<'\n';
        return 0;

    }
    if(s == "VVVVVVVVVVVVVVVVCCCCCCCCCC" && n == 200 && m == 2000)
        cout<<ch<<" "<<who<<" "<<inp[ch]<<endl;
    rep(i,1,2*n) a[i]=-1;
    rep(i,1,ch-1){
        ll ps=inp[i]-'a'+1;
        if(s[ps] == 'V') colora(i+n);
        else colora(i);
    }

    ll ps=inp[ch]-'a'+1;
    if(who) colora(ch+n);
    else colora(ch);
    inp[ch]='a'+nx[ps][who]-1;

    if(ch == n){
        cout<<change(inp)<<'\n';
        return 0;
    }

    char cf,ctr;
    if(s[1] == 'V') ctr='a',cf='a'+nx[1][0]-1;
    else cf='a',ctr='a'+nx[1][1]-1;

    ch++;
    rep(i,ch,n){
        rep(j,1,2*n) b[j]=a[j];
        if(cf == 'a'){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i);
                }
                else{
                    inp[i]=ctr;
                    colora(i+n);
                }
            }
            else{
                inp[i]=ctr;
                colora(i+n);
            }
        }
        else{
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i+n);
                }
                else{
                    inp[i]=cf;
                    colora(i);
                }
            }
            else{
                inp[i]=cf;
                colora(i);
            }
        }
    }
    cout<<change(inp)<<'\n';
}


#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
string s,inp;
ll n,m,nx[27][2],a[405],b[405];
vll g[405],gc[405];
bool pos;

void color(ll st){
    b[st]=1;
    if(st <= n) b[st+n]=0;
    else b[st-n]=0;
    for(ll v:g[st]) {
        if(b[v] == -1) color(v);
        else if(b[v] == 0) pos=0;
    }
}
void colora(ll st){
    a[st]=1;
    if(st <= n) a[st+n]=0;
    else a[st-n]=0;
    for(ll v:g[st]) {
        if(a[v] == -1) colora(v);
        else if(a[v] == 0) pos=0;
    }
}
vll path;
ll cmpno,cmp[405],mark[405];
void dfs(ll st){
    mark[st]=1;
    for(ll v:g[st]) if(b[v] == -1 && !mark[v]) dfs(v);
    path.pb(st);
}
void dfsc(ll st){
    cmp[st]=cmpno;
    for(ll v:gc[st]) if(cmp[v] == -1) dfsc(v);
}
void check(ll st){
    if(st > n )return;
    path.clear();
    rep(i,1,2*n ) mark[i]=0;

    rep(i,st,2*n) if(!mark[st] && b[st] == -1) dfs(st);
    reverse(path.begin(),path.end());

    rep(i,1,2*n) cmp[i]=-1;
    cmpno = 0;
    for(ll v:path){
        if(cmp[v] != -1) continue;
        ++cmpno;
        dfsc(v);
    }
    for(ll v:path){
        if(v <= n && cmp[v] == cmp[v+n]) pos=0;
        if(v > n && cmp[v] == cmp[v-n]) pos=0;
    }
}
string change(string inp){
    string ret;
    rep(i,1,n) ret+=inp[i];
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    ll k = s.size();
    s="$"+s;
    nx[k][0]=nx[k][1]=k+5;
    rev(i,k-1,1){
        if(s[i+1] == 'V') nx[i][1]=i+1,nx[i][0]=nx[i+1][0];
        else nx[i][0]=i+1,nx[i][1]=nx[i+1][1];
    }
    ll tc=0;
    rep(i,1,k) if(s[i] == 'V') tc++;

    cin>>n>>m;
    rep(i,1,m){
        ll p1,p2;char v1,v2;
        cin>>p1>>v1>>p2>>v2;
        if(v1 == 'V' && v2 == 'V'){
            g[p1+n].pb(p2+n);
            g[p2].pb(p1);

            gc[p2+n].pb(p1+n);
            gc[p1].pb(p2);
        }
        else if(v1 == 'V'){
            g[p1+n].pb(p2);
            g[p2+n].pb(p1);

            gc[p2].pb(p1+n);
            gc[p1].pb(p2+n);
        }
        else if(v2 == 'V'){
            g[p1].pb(p2+n);
            g[p2].pb(p1+n);

            gc[p2+n].pb(p1);
            gc[p1+n].pb(p2);
        }
        else{
            g[p1].pb(p2);
            g[p2+n].pb(p1+n);

            gc[p2].pb(p1);
            gc[p1+n].pb(p2+n);
        }
    }
    cin>>inp;inp="$"+inp;

    if(!tc || tc == k){
        if(!tc) rep(i,1,n) a[i]=1;
        else rep(i,n+1,2*n) a[i]=1;
        bool notpos=0;
        rep(i,1,2*n) if(a[i]){
            for(ll v:g[i]) if(!a[v]) notpos=1;
        }
        if(notpos ) cout<<-1<<'\n';
        else cout<<change(inp)<<'\n';
        return 0;
    }

    rep(i,1,2*n) a[i]=-1;
    ll ch = 0,who=-1;

    pos=1;
    rep(i,1,n){
        rep(j,1,2*n) b[j]=a[j];

        ll ps=inp[i]-'a'+1;
        bool is0=0;
        if(nx[ps][0] <= k){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    who=0;ch=i;is0=1;
                }
            }
        }
        if(nx[ps][1] <= k){
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    ch=i;
                    if(!is0) who=1;
                    else if(nx[ps][1] < nx[ps][0]) who=1;
                }
            }
        }
        pos=1;
        if(s[ps] == 'V'){
            colora(i+n);
            if(!pos) break;
        }
        else{
            colora(i);
            if(!pos) break;
        }
    }
    if(pos) {
        cout<<change(inp)<<'\n';
        return 0;
    }
    if(!ch){
        cout<<-1<<'\n';
        return 0;
    }
    rep(i,1,2*n) a[i]=-1;
    rep(i,1,ch-1){
        ll ps=inp[i]-'a'+1;
        if(s[ps] == 'V') colora(i+n);
        else colora(i);
    }

    ll ps=inp[ch]-'a'+1;
    if(who) colora(ch+n);
    else colora(ch);
    inp[ch]='a'+nx[ps][who]-1;

    if(ch == n){
        cout<<change(inp)<<'\n';
        return 0;
    }

    char cf,ctr;
    if(s[1] == 'V') ctr='a',cf=nx[1][0];
    else cf='a',ctr=nx[1][1];

    ch++;
    rep(i,ch,n){
        rep(j,1,2*n) b[j]=a[j];
        if(cf == 'a'){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i);
                }
                else{
                    inp[i]=ctr;
                    colora(i+n);
                }
            }
            else{
                inp[i]=ctr;
                colora(i+n);
            }
        }
        else{
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i+n);
                }
                else{
                    inp[i]=cf;
                    colora(i);
                }
            }
            else{
                inp[i]=cf;
                colora(i);
            }
        }
    }
    cout<<change(inp)<<'\n';
}


#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
string s,inp;
ll n,m,nx[27][2],a[405],b[405];
vll g[405],gc[405];
bool pos;

void color(ll st){
    b[st]=1;
    if(st <= n) b[st+n]=0;
    else b[st-n]=0;
    for(ll v:g[st]) {
        if(b[v] == -1) color(v);
        else if(b[v] == 0) pos=0;
    }
}
void colora(ll st){
    a[st]=1;
    if(st <= n) a[st+n]=0;
    else a[st-n]=0;
    for(ll v:g[st]) {
        if(a[v] == -1) colora(v);
        else if(a[v] == 0) pos=0;
    }
}
vll path;
ll cmpno,cmp[405],mark[405];
void dfs(ll st){
    mark[st]=1;
    for(ll v:g[st]) if(b[v] == -1 && !mark[v]) dfs(v);
    path.pb(st);
}
void dfsc(ll st){
    cmp[st]=cmpno;
    for(ll v:gc[st]) if(b[v] == -1 && cmp[v] == -1) dfsc(v);
}
void check(ll st){
    if(st > n ) return;
    path.clear();
    rep(i,1,2*n ) mark[i]=0;

    rep(i,st,2*n) if(!mark[i] && b[i] == -1) dfs(i);
    reverse(path.begin(),path.end());

    rep(i,1,2*n) cmp[i]=-1;
    cmpno = 0;
    for(ll v:path){
        if(cmp[v] != -1) continue;
        if(b[v] != -1) continue;
        ++cmpno;
        dfsc(v);
    }
    for(ll v:path){
        if(v <= n && cmp[v] == cmp[v+n]) pos=0;
        if(v > n && cmp[v] == cmp[v-n]) pos=0;
    }
}
string change(string inp){
    string ret;
    rep(i,1,n) ret+=inp[i];
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    ll k = s.size();
    s="$"+s;
    nx[k][0]=nx[k][1]=k+5;
    rev(i,k-1,1){
        if(s[i+1] == 'V') nx[i][1]=i+1,nx[i][0]=nx[i+1][0];
        else nx[i][0]=i+1,nx[i][1]=nx[i+1][1];
    }
    ll tc=0;
    rep(i,1,k) if(s[i] == 'V') tc++;

    cin>>n>>m;
    rep(i,1,m){
        ll p1,p2;char v1,v2;
        cin>>p1>>v1>>p2>>v2;
        if(v1 == 'V' && v2 == 'V'){
            g[p1+n].pb(p2+n);
            g[p2].pb(p1);

            gc[p2+n].pb(p1+n);
            gc[p1].pb(p2);
        }
        else if(v1 == 'V'){
            g[p1+n].pb(p2);
            g[p2+n].pb(p1);

            gc[p2].pb(p1+n);
            gc[p1].pb(p2+n);
        }
        else if(v2 == 'V'){
            g[p1].pb(p2+n);
            g[p2].pb(p1+n);

            gc[p2+n].pb(p1);
            gc[p1+n].pb(p2);
        }
        else{
            g[p1].pb(p2);
            g[p2+n].pb(p1+n);

            gc[p2].pb(p1);
            gc[p1+n].pb(p2+n);
        }
    }
    cin>>inp;inp="$"+inp;

    if(!tc || tc == k){
        if(!tc) rep(i,1,n) a[i]=1;
        else rep(i,n+1,2*n) a[i]=1;
        bool notpos=0;
        rep(i,1,2*n) if(a[i]){
            for(ll v:g[i]) if(!a[v]) notpos=1;
        }
        if(notpos ) cout<<-1<<'\n';
        else cout<<change(inp)<<'\n';
        return 0;
    }

    rep(i,1,2*n) a[i]=-1;
    ll ch = 0,who=-1;

    pos=1;
    rep(i,1,n){
        rep(j,1,2*n) b[j]=a[j];

        ll ps=inp[i]-'a'+1;
        bool is0=0;
        if(nx[ps][0] <= k){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    who=0;ch=i;is0=1;
                }
            }
        }
        rep(j,1,2*n) b[j]=a[j];
        if(nx[ps][1] <= k){
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    ch=i;
                    if(!is0) who=1;
                    else if(nx[ps][1] < nx[ps][0]) who=1;
                }
            }
        }
        pos=1;
        if(s[ps] == 'V'){
            colora(i+n);
            if(!pos) break;
        }
        else{
            colora(i);
            if(!pos) break;
        }
    }
    if(pos) {
        cout<<change(inp)<<'\n';
        return 0;
    }
    if(!ch){
        cout<<-1<<'\n';
        return 0;

    }
  //  if(s == "VVVVVVVVVVVVVVVVCCCCCCCCCC" && n == 200 && m == 2000)
    //    cout<<ch<<" "<<who<<" "<<inp[ch]<<'\n';
    rep(i,1,2*n) a[i]=-1;
    rep(i,1,ch-1){
        ll ps=inp[i]-'a'+1;
        if(s[ps] == 'V') colora(i+n);
        else colora(i);
    }

    ll ps=inp[ch]-'a'+1;
    if(who) colora(ch+n);
    else colora(ch);
    inp[ch]='a'+nx[ps][who]-1;

    if(ch == n){
        cout<<change(inp)<<'\n';
        return 0;
    }

    char cf,ctr;
    if(s[1] == 'V') ctr='a',cf='a'+nx[1][0]-1;
    else cf='a',ctr='a'+nx[1][1]-1;

    ch++;
    rep(i,ch,n){
        rep(j,1,2*n) b[j]=a[j];
        if(cf == 'a'){
            pos=1;
            color(i);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i);
                }
                else{
                    inp[i]=ctr;
                    colora(i+n);
                }
            }
            else{
                inp[i]=ctr;
                colora(i+n);
            }
        }
        else{
            pos=1;
            color(i+n);
            if(pos){
                check(i+1);
                if(pos) {
                    inp[i]='a';
                    colora(i+n);
                }
                else{
                    inp[i]=cf;
                    colora(i);
                }
            }
            else{
                inp[i]=cf;
                colora(i);
            }
        }
    }
    cout<<change(inp)<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=405,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int L,n,m,typ[N];
char ch[N],s[N],ans[N];
namespace g{

int cnt,h[N],bel[N],dfn[N],low[N],top,stk[N];
vector<int> e[N];
void add(int x,char c,int y,char d){
	x=(x*2)^(c=='V');
	y=(y*2)^(d=='V');
	e[x].push_back(y);
	e[y^1].push_back(x^1);
}
void del(int x,char c,int y,char d){
	x=(x*2)^(c=='V');
	y=(y*2)^(d=='V');
	e[x].pop_back();
	e[y^1].pop_back();
}
void tarjan(int x){
	h[x]=1;stk[++top]=x;dfn[x]=low[x]=++cnt;
	for (auto y : e[x])
	if (!h[y]) {tarjan(y);low[x]=min(low[x],low[y]);}
	else if (h[y]==1) low[x]=min(low[x],dfn[y]);
	if (dfn[x]==low[x]){
		while (stk[top]!=x) {h[stk[top]]=2;bel[stk[top--]]=x;}
		h[stk[top]]=2;bel[stk[top--]]=x;
	}
}
bool check(){
	cnt=top=0;
	memset(h,0,sizeof(h));
	for (int i=2;i<=n*2+1;i++)
	if (!h[i]) tarjan(i);
	for (int i=1;i<=n;i++)
	if (bel[i*2]==bel[i*2+1]) return false;
	return true;
}
};
bool chk(int len){
	if (len==n) return g::check();
	int i=len+1,fl=0;
	for (int c=s[i]-'a'+1;c<L;c++){
		if (fl&(1<<typ[c])) continue;
		fl+=(1<<typ[c]);
		g::add(i,'V'+'C'-ch[c],i,ch[c]);
		if (g::check()) {ans[i]='a'+c;return true;}
		g::del(i,'V'+'C'-ch[c],i,ch[c]);
	}
	return false;
}
void getans(){
	int i;
	for (i=1;i<=n;i++) g::add(i,'V'+'C'-ch[s[i]-'a'],i,ch[s[i]-'a']),ans[i]=s[i];
	for (i=n;i;i--){
		if (chk(i)) break;
		g::del(i,'V'+'C'-ch[s[i]-'a'],i,ch[s[i]-'a']);
	}
	if (!chk(i)) {puts("-1");exit(0);}
	for (i=i+2;i<=n;i++){
		int fl=0;
		for (int c=0;c<L;c++){
			if (fl&(1<<typ[c])) continue;
			fl+=(1<<typ[c]);
			g::add(i,'V'+'C'-ch[c],i,ch[c]);
			if (g::check()) {ans[i]='a'+c;break;}
			g::del(i,'V'+'C'-ch[c],i,ch[c]);
		}
	}
}
int main(){
	scanf(" %s %d %d",ch,&n,&m);
	L=strlen(ch);
	for (int i=0;i<L;i++) typ[i]=(ch[i]=='V');
	for (int i=1;i<=m;i++){
		int x,y;char c,d;
		scanf("%d %c %d %c",&x,&c,&y,&d);
		g::add(x,c,y,d);
	}
	scanf(" %s",s+1);
	getans();
	printf("%s\n",ans+1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=405,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int L,n,m,typ[N];
char ch[N],s[N],ans[N];
namespace g{

int cnt,h[N],bel[N],dfn[N],low[N],top,stk[N];
vector<int> e[N];
void add(int x,char c,int y,char d){
	x=(x*2)^(c=='V');
	y=(y*2)^(d=='V');
	e[x].push_back(y);
	e[y^1].push_back(x^1);
}
void del(int x,char c,int y,char d){
	x=(x*2)^(c=='V');
	y=(y*2)^(d=='V');
	e[x].pop_back();
	e[y^1].pop_back();
}
void tarjan(int x){
	h[x]=1;stk[++top]=x;dfn[x]=low[x]=++cnt;
	for (auto y : e[x])
	if (!h[y]) {tarjan(y);low[x]=min(low[x],low[y]);}
	else if (h[y]==1) low[x]=min(low[x],dfn[y]);
	if (dfn[x]==low[x]){
		while (stk[top]!=x) {h[stk[top]]=2;bel[stk[top--]]=x;}
		h[stk[top]]=2;bel[stk[top--]]=x;
	}
}
bool check(){
	cnt=top=0;
	memset(h,0,sizeof(h));
	for (int i=2;i<=n*2+1;i++)
	if (!h[i]) tarjan(i);
	for (int i=1;i<=n;i++)
	if (bel[i*2]==bel[i*2+1]) return false;
	return true;
}
};
bool chk(int len){
	if (len==n) return g::check();
	int i=len+1,fl=0;
	for (int c=s[i]-'a'+1;c<L;c++){
		if (fl&(1<<typ[c])) continue;
		fl+=(1<<typ[c]);
		g::add(i,'V'+'C'-ch[c],i,ch[c]);
		if (g::check()) {ans[i]='a'+c;return true;}
		g::del(i,'V'+'C'-ch[c],i,ch[c]);
	}
	return false;
}
void getans(){
	int i;
	for (i=1;i<=n;i++) g::add(i,'V'+'C'-ch[s[i]-'a'],i,ch[s[i]-'a']),ans[i]=s[i];
	for (i=n;i;i--){
		if (chk(i)) break;
		g::del(i,'V'+'C'-ch[s[i]-'a'],i,ch[s[i]-'a']);
	}
	if (!chk(i)) {puts("-1");exit(0);}
	for (i=i+2;i<=n;i++){
		int fl=0;
		for (int c=0;c<L;c++){
			if (fl&(1<<typ[c])) continue;
			fl+=(1<<typ[c]);
			g::add(i,'V'+'C'-ch[c],i,ch[c]);
			if (g::check()) {ans[i]='a'+c;break;}
			g::del(i,'V'+'C'-ch[c],i,ch[c]);
		}
	}
}
int main(){
	scanf(" %s %d %d",ch,&n,&m);
	L=strlen(ch);
	for (int i=0;i<L;i++) typ[i]=(ch[i]=='V');
	for (int i=1;i<=n;i++){
		int x,y;char c,d;
		scanf("%d %c %d %c",&x,&c,&y,&d);
		g::add(x,c,y,d);
	}
	scanf(" %s",s+1);
	getans();
	printf("%s\n",ans+1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=405,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int L,n,m,typ[N];
char ch[N],s[N],ans[N];
namespace g{

int cnt,h[N],bel[N],dfn[N],low[N],top,stk[N];
vector<int> e[N];
void add(int x,char c,int y,char d){
	x=(x*2)^(c=='V');
	y=(y*2)^(d=='V');
	e[x].push_back(y);
	e[y^1].push_back(x^1);
}
void del(int x,char c,int y,char d){
	x=(x*2)^(c=='V');
	y=(y*2)^(d=='V');
	e[x].pop_back();
	e[y^1].pop_back();
}
void tarjan(int x){
	h[x]=1;stk[++top]=x;dfn[x]=low[x]=++cnt;
	for (auto y : e[x])
	if (!h[y]) {tarjan(y);low[x]=min(low[x],low[y]);}
	else if (h[y]==1) low[x]=min(low[x],dfn[y]);
	if (dfn[x]==low[x]){
		while (stk[top]!=x) {h[stk[top]]=2;bel[stk[top--]]=x;}
		h[stk[top]]=2;bel[stk[top--]]=x;
	}
}
bool check(){
	cnt=top=0;
	memset(h,0,sizeof(h));
	for (int i=2;i<=n*2+1;i++)
	if (!h[i]) tarjan(i);
	for (int i=1;i<=n;i++)
	if (bel[i*2]==bel[i*2+1]) return false;
	return true;
}
};
bool chk(int len){
	if (len==n) return g::check();
	int i=len+1,fl=0;
	for (int c=s[i]-'a'+1;c<L;c++){
		if (fl&(1<<typ[c])) continue;
		fl+=(1<<typ[c]);
		g::add(i,'V'+'C'-ch[c],i,ch[c]);
		if (g::check()) {ans[i]='a'+c;return true;}
		g::del(i,'V'+'C'-ch[c],i,ch[c]);
	}
	return false;
}
void getans(){
	int i;
	for (i=1;i<=n;i++) g::add(i,'V'+'C'-ch[s[i]-'a'],i,ch[s[i]-'a']),ans[i]=s[i];
	for (i=n;i;i--){
		if (chk(i)) break;
		g::del(i,'V'+'C'-ch[s[i]-'a'],i,ch[s[i]-'a']);
	}
	if (!chk(i)) {puts("-1");exit(0);}
	for (i=i+2;i<=n;i++){
		int fl=0;
		for (int c=0;c<L;c++){
			if (fl&(1<<typ[c])) continue;
			fl+=(1<<typ[c]);
			g::add(i,'V'+'C'-ch[c],i,ch[c]);
			if (g::check()) {ans[i]='a'+c;fl+=4;break;}
			g::del(i,'V'+'C'-ch[c],i,ch[c]);
		}
		if (!(fl&4)){puts("-1");exit(0);}
	}
}
int main(){
	scanf(" %s %d %d",ch,&n,&m);
	L=strlen(ch);
	for (int i=0;i<L;i++) typ[i]=(ch[i]=='V');
	for (int i=1;i<=m;i++){
		int x,y;char c,d;
		scanf("%d %c %d %c",&x,&c,&y,&d);
		g::add(x,c,y,d);
	}
	scanf(" %s",s+1);
	getans();
	printf("%s\n",ans+1);
	return 0;
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)159202;
const int MAXS = (int)502;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
string alpha, s;
int n, m;
int pos1[MAXN], pos2[MAXN], scc[MAXS], visited[MAXS];
char c1[MAXN], c2[MAXN];
vector<int> G[MAXS], rev[MAXS];
vector<int> topol;
vector<pair<int, int> > tempo_clause;
int compo = 0;
int nt(int a)
{
	if(a < n)
		return a + n;
	else
		return a - n;
}
void add_edge(int u, int v)
{
	G[u].push_back(nt(v));
	G[v].push_back(nt(u));
	rev[nt(v)].push_back(u);
	rev[nt(u)].push_back(v);
}
void del_edge(int u, int v)
{
	G[u].pop_back();
	G[v].pop_back();
	rev[nt(v)].pop_back();
	rev[nt(u)].pop_back();
}
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v])
			dfs(v);
	topol.push_back(u);
}
void dfs2(int u)
{
	scc[u] = compo;
	visited[u] = 1;
	for (auto v : rev[u])
		if(!visited[v])
			dfs2(v);
}
bool sat()
{
	topol.clear();
	memset(scc, -1, sizeof scc);
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < 2 * n; i++)
		if(!visited[i])
			dfs(i);
	memset(visited, 0, sizeof visited);
	compo = 0;
	for (int i = topol.size() - 1; i >= 0; i--)
		if(!visited[topol[i]])
			dfs2(topol[i]), compo++;
	for (int i = 0; i < n; i++)
		if(scc[i] == scc[nt(i)])
		{
			return 0;
		}
	return 1;
}
void Add(int u, int v)
{
	tempo_clause.push_back({u, v});
	add_edge(u, v);
}
void Erase()
{
	int u = tempo_clause.back().first, v = tempo_clause.back().second;
	del_edge(u, v);
	tempo_clause.pop_back();
}
int main()
{
	cin >> alpha;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %c %d %c", &pos1[i], &c1[i], &pos2[i], &c2[i]);
		pos1[i]--, pos2[i]--;
		int a1 = pos1[i];
		if(c1[i] == 'C')
			a1 += n;

		int a2 = pos2[i];
		if(c2[i] == 'C')
			a2 += n;
		Add(nt(a1), a2);
	}
	cin >> s;
	//corner 1 : if all alphabet are C.
	int V = 0, C = 0;
	for (int i = 0; i < alpha.size(); i++)
		if(alpha[i] == 'V')
			V++;
		else
			C++;
	if(V == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'C' && c2[i] == 'V')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//corner 2 : if all alphabet are V.
	if(C == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'V' && c2[i] == 'C')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//

	for (int i = 0; i < n; i++)
	{
		int a1 = i;
		if(alpha[s[i] - 'a'] == 'C')
			a1 += n;
		Add(a1, a1);
	}
	//find first place where it should change.
	if(sat())
		return cout << s, 0;

	int first = -1;
	char ptr;
	for (int i = n - 1; i >= 0; i--)
	{
		if(first != -1)
			break;
		Erase();
		for (char cur = (char)(s[i] + 1); cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			Add(a1, a1);
			if(sat())
			{
				first = i, ptr = cur;
				break;
			}
			Erase();
		}
	}
	if(first == -1)
	{
		puts("-1");
		return 0;
	}
	s[first] = ptr;
	for (int i = first + 1; i < n; i++)
	{
		char cnt;
		for (char cur = 'a'; cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			Add(a1, a1);
			if(sat())
			{
				s[i] = cur;
				break;
			}
			Erase();
		}
	}
	cout << s;
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
string alpha, s;
int n, m;
int pos1[MAXN], pos2[MAXN], scc[MAXN], visited[MAXN];
char c1[MAXN], c2[MAXN];
vector<pair<int, int> > clause;
vector<int> G[MAXN], rev[MAXN];
vector<int> topol;
int compo = 0;
int nt(int a)
{
	if(a < n)
		return a + n;
	else
		return a - n;
}
void make_graph()
{
	for (int i = 0; i < MAXN; i++)
		G[i].clear(), rev[i].clear();
	for (auto u : clause)
	{
		G[u.first].push_back(nt(u.second));
		G[u.second].push_back(nt(u.first));
		rev[nt(u.second)].push_back(u.first);
		rev[nt(u.first)].push_back(u.second);
	}
}
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v])
			dfs(v);
	topol.push_back(u);
}
void dfs2(int u)
{
	scc[u] = compo;
	visited[u] = 1;
	for (auto v : rev[u])
		if(!visited[v])
			dfs2(v);
}
bool sat()
{
	make_graph();
	topol.clear();
	memset(scc, -1, sizeof scc);
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < 2 * n; i++)
		if(!visited[i])
			dfs(i);
	memset(visited, 0, sizeof visited);
	compo = 0;
	for (int i = topol.size() - 1; i >= 0; i--)
		if(!visited[topol[i]])
			dfs2(topol[i]), compo++;
	for (int i = 0; i < n; i++)
		if(scc[i] == scc[nt(i)])
		{
			return 0;
		}
	return 1;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> alpha;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> pos1[i] >> c1[i] >> pos2[i] >> c2[i];
		pos1[i]--, pos2[i]--;
		int a1 = pos1[i];
		if(c1[i] == 'C')
			a1 += n;

		int a2 = pos2[i];
		if(c2[i] == 'C')
			a2 += n;
		clause.push_back({nt(a1), a2});
	}
	cin >> s;
	if(m == 119400)
		cout << sat() << endl;
	//corner 1 : if all alphabet are C.
	int V = 0, C = 0;
	for (int i = 0; i < alpha.size(); i++)
		if(alpha[i] == 'V')
			V++;
		else
			C++;
	if(V == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'C' && c2[i] == 'V')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//corner 2 : if all alphabet are V.
	if(C == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'V' && c2[i] == 'C')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		int a1 = i;
		if(alpha[s[i] - 'a'] == 'C')
			a1 += n;
		clause.push_back({a1, a1});
	}
	//find first place where it should change.
	if(sat())
		return cout << s, 0;
	int first = -1;
	char ptr;
	for (int i = s.size() - 1; i >= 0; i--)
	{
		if(first != -1)
			break;
		clause.pop_back();
		for (char cur = (char)(s[i] + 1); cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			clause.push_back({a1, a1});
			if(sat())
			{
				first = i, ptr = cur;
				break;
			}
			clause.pop_back();
		}
	}
	if(first == -1)
		return cout << -1, 0;
	s[first] = ptr;
	for (int i = first + 1; i < n; i++)
	{
		char cnt;
		for (char cur = 'a'; cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			clause.push_back({a1, a1});
			if(sat())
			{
				s[i] = cur;
				break;
			}
			clause.pop_back();
		}
	}
	cout << s;
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)159202;
const int MAXS = (int)202;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
string alpha, s;
int n, m;
int pos1[MAXN], pos2[MAXN], scc[MAXS], visited[MAXS];
char c1[MAXN], c2[MAXN];
vector<int> G[MAXS], rev[MAXS];
vector<int> topol;
vector<pair<int, int> > tempo_clause;
int compo = 0;
int nt(int a)
{
	if(a < n)
		return a + n;
	else
		return a - n;
}
void add_edge(int u, int v)
{
	G[u].push_back(nt(v));
	G[v].push_back(nt(u));
	rev[nt(v)].push_back(u);
	rev[nt(u)].push_back(v);
}
void del_edge(int u, int v)
{
	G[u].pop_back();
	G[v].pop_back();
	rev[nt(v)].pop_back();
	rev[nt(u)].pop_back();
}
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v])
			dfs(v);
	topol.push_back(u);
}
void dfs2(int u)
{
	scc[u] = compo;
	visited[u] = 1;
	for (auto v : rev[u])
		if(!visited[v])
			dfs2(v);
}
bool sat()
{
	topol.clear();
	memset(scc, -1, sizeof scc);
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < 2 * n; i++)
		if(!visited[i])
			dfs(i);
	memset(visited, 0, sizeof visited);
	compo = 0;
	for (int i = topol.size() - 1; i >= 0; i--)
		if(!visited[topol[i]])
			dfs2(topol[i]), compo++;
	for (int i = 0; i < n; i++)
		if(scc[i] == scc[nt(i)])
		{
			return 0;
		}
	return 1;
}
void Add(int u, int v)
{
	tempo_clause.push_back({u, v});
	add_edge(u, v);
}
void Erase()
{
	int u = tempo_clause.back().first, v = tempo_clause.back().second;
	del_edge(u, v);
}
int main()
{
	cin >> alpha;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> pos1[i] >> c1[i] >> pos2[i] >> c2[i];
		pos1[i]--, pos2[i]--;
		int a1 = pos1[i];
		if(c1[i] == 'C')
			a1 += n;

		int a2 = pos2[i];
		if(c2[i] == 'C')
			a2 += n;
		Add(nt(a1), a2);
	}
	cin >> s;
	//corner 1 : if all alphabet are C.
	int V = 0, C = 0;
	for (int i = 0; i < alpha.size(); i++)
		if(alpha[i] == 'V')
			V++;
		else
			C++;
	if(V == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'C' && c2[i] == 'V')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//corner 2 : if all alphabet are V.
	if(C == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'V' && c2[i] == 'C')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		int a1 = i;
		if(alpha[s[i] - 'a'] == 'C')
			a1 += n;
		Add(a1, a1);
	}
	//find first place where it should change.
	if(sat())
		return cout << s, 0;

	int first = -1;
	char ptr;
	for (int i = s.size() - 1; i >= 0; i--)
	{
		if(first != -1)
			break;
		Erase();
		for (char cur = (char)(s[i] + 1); cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			Add(a1, a1);
			if(sat())
			{
				first = i, ptr = cur;
				break;
			}
			Erase();
		}
	}
	if(first == -1)
	{
		puts("-1");
		return 0;
	}
	s[first] = ptr;
	for (int i = first + 1; i < n; i++)
	{
		char cnt;
		for (char cur = 'a'; cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			Add(a1, a1);
			if(sat())
			{
				s[i] = cur;
				break;
			}
			Erase();
		}
	}
	cout << s;
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
string alpha, s;
int n, m;
int pos1[MAXN], pos2[MAXN], scc[MAXN], visited[MAXN];
char c1[MAXN], c2[MAXN];
vector<pair<int, int> > clause;
vector<int> G[MAXN], rev[MAXN];
vector<int> topol;
int compo = 0;
int nt(int a)
{
	if(a < n)
		return a + n;
	else
		return a - n;
}
void make_graph()
{
	for (int i = 0; i < MAXN; i++)
		G[i].clear(), rev[i].clear();
	for (auto u : clause)
	{
		G[u.first].push_back(nt(u.second));
		G[u.second].push_back(nt(u.first));
		rev[nt(u.second)].push_back(u.first);
		rev[nt(u.first)].push_back(u.second);
	}
}
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v])
			dfs(v);
	topol.push_back(u);
}
void dfs2(int u)
{
	scc[u] = compo;
	visited[u] = 1;
	for (auto v : rev[u])
		if(!visited[v])
			dfs2(v);
}
bool sat()
{
	make_graph();
	topol.clear();
	memset(scc, -1, sizeof scc);
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < 4 * n; i++)
		if(!visited[i])
			dfs(i);
	memset(visited, 0, sizeof visited);
	compo = 0;
	for (int i = topol.size() - 1; i >= 0; i--)
		if(!visited[topol[i]])
			dfs2(topol[i]), compo++;
	for (int i = 0; i < 2 * n; i++)
		if(scc[i] == scc[nt(i)])
		{
			return 0;
		}
	return 1;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> alpha;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> pos1[i] >> c1[i] >> pos2[i] >> c2[i];
		pos1[i]--, pos2[i]--;
		int a1 = pos1[i];
		if(c1[i] == 'C')
			a1 += n;

		int a2 = pos2[i];
		if(c2[i] == 'C')
			a2 += n;
		clause.push_back({nt(a1), a2});
	}
	cin >> s;
	//corner 1 : if all alphabet are C.
	int V = 0, C = 0;
	for (int i = 0; i < alpha.size(); i++)
		if(alpha[i] == 'V')
			V++;
		else
			C++;
	if(V == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'C' && c2[i] == 'V')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//corner 2 : if all alphabet are V.
	if(C == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'V' && c2[i] == 'C')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		int a1 = i;
		if(alpha[s[i] - 'a'] == 'C')
			a1 += n;
		clause.push_back({a1, a1});
	}
	//find first place where it should change.
	if(sat())
		return cout << s, 0;
	int first = -1;
	char ptr;
	for (int i = s.size() - 1; i >= 0; i--)
	{
		if(first != -1)
			break;
		clause.pop_back();
		for (char cur = (char)(s[i] + 1); cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			clause.push_back({a1, a1});
			if(sat())
			{
				first = i, ptr = cur;
				break;
			}
			clause.pop_back();
		}
	}
	if(first == -1)
		return cout << -1, 0;
	s[first] = ptr;
	for (int i = first + 1; i < n; i++)
	{
		char cnt;
		for (char cur = 'a'; cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			clause.push_back({a1, a1});
			if(sat())
			{
				s[i] = cur;
				break;
			}
			clause.pop_back();
		}
	}
	cout << s;
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)159202;
const int MAXS = (int)202;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
string alpha, s;
int n, m;
int pos1[MAXN], pos2[MAXN], scc[MAXS], visited[MAXS];
char c1[MAXN], c2[MAXN];
vector<int> G[MAXS], rev[MAXS];
vector<int> topol;
vector<pair<int, int> > tempo_clause;
int compo = 0;
int nt(int a)
{
	if(a < n)
		return a + n;
	else
		return a - n;
}
void add_edge(int u, int v)
{
	G[u].push_back(nt(v));
	G[v].push_back(nt(u));
	rev[nt(v)].push_back(u);
	rev[nt(u)].push_back(v);
}
void del_edge(int u, int v)
{
	G[u].pop_back();
	G[v].pop_back();
	rev[nt(v)].pop_back();
	rev[nt(u)].pop_back();
}
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v])
			dfs(v);
	topol.push_back(u);
}
void dfs2(int u)
{
	scc[u] = compo;
	visited[u] = 1;
	for (auto v : rev[u])
		if(!visited[v])
			dfs2(v);
}
bool sat()
{
	topol.clear();
	memset(scc, -1, sizeof scc);
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < 2 * n; i++)
		if(!visited[i])
			dfs(i);
	memset(visited, 0, sizeof visited);
	compo = 0;
	for (int i = topol.size() - 1; i >= 0; i--)
		if(!visited[topol[i]])
			dfs2(topol[i]), compo++;
	for (int i = 0; i < n; i++)
		if(scc[i] == scc[nt(i)])
		{
			return 0;
		}
	return 1;
}
int main()
{
	cin >> alpha;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> pos1[i] >> c1[i] >> pos2[i] >> c2[i];
		pos1[i]--, pos2[i]--;
		int a1 = pos1[i];
		if(c1[i] == 'C')
			a1 += n;

		int a2 = pos2[i];
		if(c2[i] == 'C')
			a2 += n;
		tempo_clause.push_back({nt(a1), a2});
		add_edge(nt(a1), a2);
	}
	cin >> s;
	//corner 1 : if all alphabet are C.
	int V = 0, C = 0;
	for (int i = 0; i < alpha.size(); i++)
		if(alpha[i] == 'V')
			V++;
		else
			C++;
	if(V == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'C' && c2[i] == 'V')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//corner 2 : if all alphabet are V.
	if(C == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'V' && c2[i] == 'C')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		int a1 = i;
		if(alpha[s[i] - 'a'] == 'C')
			a1 += n;
		tempo_clause.push_back({a1, a1});
		add_edge(a1, a1);
	}
	//find first place where it should change.
	if(sat())
		return cout << s, 0;

	int first = -1;
	char ptr;
	for (int i = s.size() - 1; i >= 0; i--)
	{
		if(first != -1)
			break;
		del_edge(tempo_clause.back().first, tempo_clause.back().second);
		tempo_clause.pop_back();
		for (char cur = (char)(s[i] + 1); cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			tempo_clause.push_back({a1, a1});
			add_edge(a1, a1);
			if(sat())
			{
				first = i, ptr = cur;
				break;
			}
			del_edge(tempo_clause.back().first, tempo_clause.back().second);
			tempo_clause.pop_back();
		}
	}
	if(first == -1)
	{
		puts("-1");
		return 0;
	}
	s[first] = ptr;
	for (int i = first + 1; i < n; i++)
	{
		char cnt;
		for (char cur = 'a'; cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			tempo_clause.push_back({a1, a1});
			add_edge(a1, a1);
			if(sat())
			{
				s[i] = cur;
				break;
			}
			del_edge(tempo_clause.back().first, tempo_clause.back().second);
			tempo_clause.pop_back();
		}
	}
	cout << s;
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)159202;
const int MAXS = (int)202;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
string alpha, s;
int n, m;
int pos1[MAXN], pos2[MAXN], scc[MAXS], visited[MAXS];
char c1[MAXN], c2[MAXN];
vector<int> G[MAXS], rev[MAXS];
vector<int> topol;
vector<pair<int, int> > tempo_clause;
int compo = 0;
int nt(int a)
{
	if(a < n)
		return a + n;
	else
		return a - n;
}
void add_edge(int u, int v)
{
	G[u].push_back(nt(v));
	G[v].push_back(nt(u));
	rev[nt(v)].push_back(u);
	rev[nt(u)].push_back(v);
}
void del_edge(int u, int v)
{
	G[u].pop_back();
	G[v].pop_back();
	rev[nt(v)].pop_back();
	rev[nt(u)].pop_back();
}
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v])
			dfs(v);
	topol.push_back(u);
}
void dfs2(int u)
{
	scc[u] = compo;
	visited[u] = 1;
	for (auto v : rev[u])
		if(!visited[v])
			dfs2(v);
}
bool sat()
{
	topol.clear();
	memset(scc, -1, sizeof scc);
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < 2 * n; i++)
		if(!visited[i])
			dfs(i);
	memset(visited, 0, sizeof visited);
	compo = 0;
	for (int i = topol.size() - 1; i >= 0; i--)
		if(!visited[topol[i]])
			dfs2(topol[i]), compo++;
	for (int i = 0; i < n; i++)
		if(scc[i] == scc[nt(i)])
		{
			return 0;
		}
	return 1;
}
int main()
{
	cin >> alpha;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d %c %d %c", &pos1[i], &c1[i], &pos2[i], &c2[i]);
		pos1[i]--, pos2[i]--;
		int a1 = pos1[i];
		if(c1[i] == 'C')
			a1 += n;

		int a2 = pos2[i];
		if(c2[i] == 'C')
			a2 += n;
		tempo_clause.push_back({nt(a1), a2});
		add_edge(nt(a1), a2);
	}
	cin >> s;
	//corner 1 : if all alphabet are C.
	int V = 0, C = 0;
	for (int i = 0; i < alpha.size(); i++)
		if(alpha[i] == 'V')
			V++;
		else
			C++;
	if(V == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'C' && c2[i] == 'V')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//corner 2 : if all alphabet are V.
	if(C == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'V' && c2[i] == 'C')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		int a1 = i;
		if(alpha[s[i] - 'a'] == 'C')
			a1 += n;
		tempo_clause.push_back({a1, a1});
		add_edge(a1, a1);
	}
	//find first place where it should change.
	if(sat())
		return cout << s, 0;

	int first = -1;
	char ptr;
	for (int i = s.size() - 1; i >= 0; i--)
	{
		if(first != -1)
			break;
		del_edge(tempo_clause.back().first, tempo_clause.back().second);
		tempo_clause.pop_back();
		for (char cur = (char)(s[i] + 1); cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			tempo_clause.push_back({a1, a1});
			add_edge(a1, a1);
			if(sat())
			{
				first = i, ptr = cur;
				break;
			}
			del_edge(tempo_clause.back().first, tempo_clause.back().second);
			tempo_clause.pop_back();
		}
	}
	if(first == -1)
	{
		puts("-1");
		return 0;
	}
	s[first] = ptr;
	for (int i = first + 1; i < n; i++)
	{
		char cnt;
		for (char cur = 'a'; cur <= (char)('a' + alpha.size() - 1); cur++)
		{
			int a1 = i;
			if(alpha[cur - 'a'] == 'C')
				a1 += n;
			tempo_clause.push_back({a1, a1});
			add_edge(a1, a1);
			if(sat())
			{
				s[i] = cur;
				break;
			}
			del_edge(tempo_clause.back().first, tempo_clause.back().second);
			tempo_clause.pop_back();
		}
	}
	cout << s;
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)159202;
const int MAXS = (int)502;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
string alpha, s;
int n, m;
int pos1[MAXN], pos2[MAXN], scc[MAXS], visited[MAXS];
char c1[MAXN], c2[MAXN];
vector<int> G[MAXS], rev[MAXS];
vector<int> topol;
vector<pair<int, int> > tempo_clause;
int smvo[30], smcon[30];
int compo = 0;
int nt(int a)
{
	if(a < n)
		return a + n;
	else
		return a - n;
}
void add_edge(int u, int v)
{
	G[u].push_back(nt(v));
	G[v].push_back(nt(u));
	rev[nt(v)].push_back(u);
	rev[nt(u)].push_back(v);
}
void del_edge(int u, int v)
{
	G[u].pop_back();
	G[v].pop_back();
	rev[nt(v)].pop_back();
	rev[nt(u)].pop_back();
}
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v])
			dfs(v);
	topol.push_back(u);
}
void dfs2(int u)
{
	scc[u] = compo;
	visited[u] = 1;
	for (auto v : rev[u])
		if(!visited[v])
			dfs2(v);
}
bool sat()
{
	topol.clear();
	memset(scc, -1, sizeof scc);
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < 2 * n; i++)
		if(!visited[i])
			dfs(i);
	memset(visited, 0, sizeof visited);
	compo = 0;
	for (int i = topol.size() - 1; i >= 0; i--)
		if(!visited[topol[i]])
			dfs2(topol[i]), compo++;
	for (int i = 0; i < n; i++)
		if(scc[i] == scc[nt(i)])
		{
			return 0;
		}
	return 1;
}
void Add(int u, int v)
{
	tempo_clause.push_back({u, v});
	add_edge(u, v);
}
void Erase()
{
	int u = tempo_clause.back().first, v = tempo_clause.back().second;
	del_edge(u, v);
	tempo_clause.pop_back();
}
int main()
{

	cin >> alpha;
	if(alpha[alpha.size() - 1] == 'V')
		smvo[alpha.size() - 1] = alpha.size() - 1, smcon[alpha.size() - 1] = infint;
	else
		smcon[alpha.size() - 1] = alpha.size() - 1, smvo[alpha.size() - 1] = infint;
	smvo[alpha.size()] = infint, smcon[alpha.size()] = infint;
	for (int i = alpha.size() - 2; i >= 0; i--)
	{
		smvo[i] = smvo[i + 1];
		smcon[i] = smcon[i + 1];
		if(alpha[i] == 'V')
			smvo[i] = i;
		else
			smcon[i] = i;
	}

	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %c %d %c", &pos1[i], &c1[i], &pos2[i], &c2[i]);
		pos1[i]--, pos2[i]--;
		int a1 = pos1[i];
		if(c1[i] == 'C')
			a1 += n;

		int a2 = pos2[i];
		if(c2[i] == 'C')
			a2 += n;
		Add(nt(a1), a2);
	}

	cin >> s;
	//corner 1 : if all alphabet are C.
	int V = 0, C = 0;
	for (int i = 0; i < alpha.size(); i++)
		if(alpha[i] == 'V')
			V++;
		else
			C++;
	if(V == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'C' && c2[i] == 'V')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//corner 2 : if all alphabet are V.
	if(C == 0)
	{
		for (int i = 0; i < m; i++)
			if(c1[i] == 'V' && c2[i] == 'C')
				return cout << -1, 0;
		cout << s;
		return 0;
	}
	//

	for (int i = 0; i < n; i++)
	{
		int a1 = i;
		if(alpha[s[i] - 'a'] == 'C')
			a1 += n;
		Add(a1, a1);
	}
	//find first place where it should change.
	if(sat())
		return cout << s, 0;

	int first = -1;
	char ptr;
	for (int i = n - 1; i >= 0; i--)
	{
		if(first != -1)
			break;
		Erase();
		int ptrsen = s[i] - 'a' + 1;
		int ptr1 = smvo[ptrsen], ptr2 = smcon[ptrsen];
		if(ptr1 < ptr2)
		{
			if(ptr1 != infint)
			{
				int a1 = i;
				Add(a1, a1);
				if(sat())
				{
					first = i, ptr = (char)('a' + ptr1);
					break;
				}
				Erase();
			}
			if(ptr2 != infint)
			{
				int a1 = i;
				a1 += n;
				Add(a1, a1);
				if(sat())
				{
					first = i, ptr = (char)('a' + ptr2);
					break;
				}
				Erase();
			}
		}
		else
		{
			if(ptr2 != infint)
			{
				int a1 = i;
				a1 += n;
				Add(a1, a1);
				if(sat())
				{
					first = i, ptr = (char)('a' + ptr2);
					break;
				}
				Erase();
			}
			if(ptr1 != infint)
			{
				int a1 = i;
				Add(a1, a1);
				if(sat())
				{
					first = i, ptr = (char)('a' + ptr1);
						break;
				}
				Erase();
			}
		}
	}
	if(first == -1)
	{
		puts("-1");
		return 0;
	}
	s[first] = ptr;
	for (int i = first + 1; i < n; i++)
	{
		int ptrsen = 0;
		int ptr1 = smvo[ptrsen], ptr2 = smcon[ptrsen];
		if(ptr1 < ptr2)
		{
			bool C1 = 0;
			if(ptr1 != infint)
			{
				int a1 = i;
				Add(a1, a1);
				if(sat())
					s[i] = (char)('a' + ptr1), C1 = 1;
				else
					Erase();
			}
			if(!C1)
			{
				int a1 = i + n;
				Add(a1, a1);
				if(sat())
					s[i] = (char)('a' + ptr2);
			}
		}
		else
		{
			bool C1 = 0;
			if(ptr2 != infint)
			{
				int a1 = i + n;
				Add(a1, a1);
				if(sat())
					s[i] = (char)('a' + ptr2), C1 = 1;
				else
					Erase();
			}
			if(!C1)
			{
				int a1 = i;
				Add(a1, a1);
				if(sat())
					s[i] = (char)('a' + ptr1);
			}
		}
	}
	cout << s;
}


///FUCKOUT
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<int, int>;

const int N = 400 + 5, M = 1e6 + 5, LG = 17, MOD = 1e9 + 7;
const int BLOCK = 1900;
const int BLOCKN = N / BLOCK + 1;
const long double EPS = 1e-7;

bitset<N> m[N];
string s, tp;
int n, l, h5a;
int get(char c){
  return tp[c-'a'] == 'V';
}
bool solve(string & s, int len){
  bitset<N> tmp;
  f(i,0,len+1)tmp|=m[i<<1|(get(s[i]))];
  f(i,0,n)
    if(tmp[i<<1] && tmp[i<<1|1])return false;
  return true;
}
int main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  cin >> tp >> n >> h5a;
  l = tp.size();

  f(i,0,h5a){
    int u, v; char  c1,c2;
    cin >> u >> c1 >> v >> c2;
    u = (u - 1) * 2 + (c1 == 'V');
    v = (v - 1) * 2 + (c2 == 'V');
    m[u][v] = m[v ^ 1][u ^ 1] = 1;
  }

  f(i,0,n+n)m[i][i] = 1;

  f(k,0,n+n)
    f(i,0,n+n)
      if(m[i][k])m[i] |= m[k];

  cin >> s;
  if(solve(s, n -  1)){
    cout << s << '\n';
    return 0;
  }

  for(int i = n - 1 ; i >= 0; --i){
    string tmp = s;
    for(char c = s[i]+1; c < 'a' + l; c++){
      tmp[i] = c;
      if(solve(tmp, i)){  ///if prefix is correct you can solve suffix
        f(k,i+1,n)
          f(k2,0,l){
            tmp[k] = k2 + 'a';
            if(solve(tmp,k))break;
          }

        if(!solve(tmp,n-1)){
          cout << "-1\n";
        } else {
          cout << tmp << '\n';
        }
        return 0;
      }

    }

  }

  cout << -1 << '\n';

  return 0;
}


///FUCKOUT
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<int, int>;

const int N = 400 + 5, M = 1e6 + 5, LG = 17, MOD = 1e9 + 7;
const int BLOCK = 1900;
const int BLOCKN = N / BLOCK + 1;
const long double EPS = 1e-7;

bitset<N> m[N];
string s, tp;
int n, l, h5a;
int get(char c){
  return tp[c-'a'] == 'V';
}
bool solve(string & s, int len){
  bitset<N> tmp;
  f(i,0,len+1)tmp|=m[i<<1|(get(s[i]))];
  f(i,0,n)
    if(tmp[i<<1] && tmp[i<<1|1])return false;
  return true;
}
int main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  cin >> tp >> n >> h5a;
  l = tp.size();

  f(i,0,h5a){
    int u, v; char  c1,c2;
    cin >> u >> c1 >> v >> c2;
    u = (u - 1) * 2 + (c1 == 'V');
    v = (v - 1) * 2 + (c2 == 'V');
    m[u][v] = m[u ^ 1][v ^ 1] = 1;
  }

  f(i,0,n+n)m[i][i] = 1;

  f(k,0,n+n)
    f(i,0,n+n)
      if(m[i][k])m[i] |= m[k];

  cin >> s;
  if(solve(s, n -  1)){
    cout << s << '\n';
    return 0;
  }

  for(int i = n - 1 ; i >= 0; --i){
    string tmp = s;
    for(char c = s[i]+1; c < 'a' + l; c++){
      tmp[i] = c;
      if(solve(tmp, i)){  ///if prefix is correct you can solve suffix
        f(k,i+1,n)
          f(k2,0,l){
            tmp[k] = k2 + 'a';
            if(solve(tmp,k))break;
          }

        if(!solve(tmp,n-1)){
          cout << "-1\n";
        } else {
          cout << tmp << '\n';
        }
        return 0;
      }

    }

  }

  cout << -1 << '\n';

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <assert.h>
using namespace std;

const int N = 410;
bool dp[N][N];
char s[N], str[N], ans[N];
int l;
bool vis[N];
int n, m;
bool flag;

void dfs(int pos, int f) {
	if (flag) return;
    if (pos == n + 1) {
        flag = true;
		printf("%s\n", ans + 1);
        return;
    }

    bool v = true, c = true;
    for (int i = 1; i < pos; i++) {
		int tmp = s[ans[i] - 'a'] == 'V';
		v &= !dp[2 * i + tmp][pos << 1];
		v &= !dp[2 * pos + 1][2 * i + 1 - tmp];
		c &= !dp[2 * i + tmp][pos << 1 | 1];
		c &= !dp[2 * pos][2 * i + 1 - tmp];
	}

    for (char i = f ? 'a': str[pos]; i < 'a' + l && !flag; i++) {
	    bool tmp = s[i - 'a'] == 'V';
	    if ((tmp && v) || (!tmp && c)) {
	        ans[pos] = i;
			dfs(pos + 1, f | (i > str[pos]));
		}
	}
}

int main()
{
	scanf("%s", s);
	l = strlen(s);
    for (int i = 0; i < l; i++)
	    vis[s[i] == 'V'] = 1;

	scanf("%d%d", &n, &m);
    if (!vis[0] || !vis[1])
	    for (int i = 1; i <= n; i++)
		    dp[2 * i + vis[0]][2 * i + 1 - vis[0]] = true;

    while (m--) {
	    char s1[3], s2[3];
	    int x, y;
	    scanf("%d%s%d%s", &x, s1, &y, s2);
        dp[2 * x + (s1[0] == 'V')][2 * y + (s2[0] == 'V')] = true;
		dp[2 * y + 1 - (s2[0] == 'V')][2 * x + 1 - (s1[0] == 'V')] = true;
	}

	for (int k = 1; k <= 2 * n; k++)
		for (int i = 1; i <= 2 * n; i++)
			for (int j = 1; j <= 2 * n; j++)
				dp[i][j] |= dp[i][k] & dp[k][j];

	scanf("%s", str + 1);
	dfs(1, 0);
	if (!flag) {
		printf("-1\n");
		return 0;
	}

	return 0;
}