#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-8;   const double PI = acos(-1.0);   const int maxn = 200 + 10;   char str[maxn];   struct TwoSat {     int n;     vector<int> G[maxn * 2];     bool mark[maxn * 2];     int S[maxn * 2], c;     bool isv[maxn];     int sz;     bool dfs(int x) {       if (mark[x ^ 1]) return false;       if (mark[x]) return true;       if (x / 2 < xi) {         int id = str[x / 2] -  a ;         if (isv[id] != (x & 1)) return false;         tmp[x / 2] = str[x / 2];       } else if (x / 2 == xi) {         int t = get_min(str[xi] -  a , (x & 1) ? true : false);         if (t == -1) return false;         tmp[x / 2] = t +  a ;       } else {         int t = get_min(-1, (x & 1) ? true : false);         if (t == -1) return false;         tmp[x / 2] = t +  a ;       }       mark[x] = true;       S[c++] = x;       for (int i = 0; i < G[x].size(); i++)         if (!dfs(G[x][i])) return false;       return true;     }     void init(int n, char *s) {       this->n = n;       for (int i = 0; i < n * 2; i++) G[i].clear();       memset(mark, false, sizeof(mark));       sz = strlen(s);       for (int i = 0; i < sz; i++) isv[i] = s[i] ==  V  ? true : false;     }     void add_clause(int x, int xval, int y, int yval) {       x = x * 2 + xval;       y = y * 2 + yval;       G[x ^ 1].push_back(y);       G[y ^ 1].push_back(x);     }     int get_min(int pos, bool c) {       for (int i = pos + 1; i < sz; i++) {         if (c == isv[i]) return i;       }       return -1;     }     char ans[maxn], tmp[maxn];     int xi;     void solve() {       bool OK = false;       for (int pos = 0; pos <= n; pos++) {         for (int x = 0; x <= 1; x++) {           xi = pos;           bool ok = false;           memset(mark, false, sizeof(mark));           strcpy(tmp, str);           if (pos < n) {             int t = get_min(str[pos] -  a , (x & 1) ? true : false);             if (t == -1) continue;             tmp[pos] = t +  a ;           }           for (int i = pos + 1; i < n; i++) tmp[i] =  a ;           c = 0;           for (int i = 0; i < n; i++) {             int x1 = (i << 1) | (isv[tmp[i] -  a ]);             if (!dfs(x1)) {               ok = true;               break;             }           }           if (n == 200) {           }           if (ok) continue;           OK = true;           tmp[n] = 0;           if (ans[0] == 0)             strcpy(ans, tmp);           else if (strcmp(tmp, ans) < 0)             strcpy(ans, tmp);         }       }       if (OK)         printf( %s n , ans);       else         printf( -1 n );     }   } sat;   int main() {     int n, m;     while (~scanf( %s , str)) {       scanf( %d%d , &n, &m);       sat.init(n, str);       for (int i = 0, x, y, xval, yval; i < m; i++) {         char t1[5], t2[5];         scanf( %d%s%d%s , &x, t1, &y, t2);         xval = t1[0] ==  V  ? 1 : 0;         yval = t2[0] ==  V  ? 1 : 0;         --x;         --y;         sat.add_clause(x, xval ^ 1, y, yval);       }       scanf( %s , str);       sat.solve();     }     return 0;   }   