#include <bits/stdc++.h>   using namespace std;   template <typename T>   void gmin(T &a, T b) {     a = a < b ? a : b;   }   template <typename T>   void gmax(T &a, T b) {     a = a > b ? a : b;   }   const int MAXV = 410;   const int MAXE = 1650;   const int INF = 0x3f3f3f3f;   struct Edge {     int to, cap, nxt, cost;     Edge() {}     Edge(int to, int cap, int nxt, int cost)         : to(to), cap(cap), nxt(nxt), cost(cost) {}   } edge[MAXE << 1];   int head[MAXV], cnt;   void initedge() {     memset(head, -1, sizeof(head));     cnt = 0;   }   inline void addedge(int from, int to, int cap, int cost) {     edge[cnt] = Edge(to, cap, head[from], cost);     head[from] = cnt++;   }   inline void addedge2(int from, int to, int cap, int cost) {     addedge(from, to, cap, cost);     addedge(to, from, 0, -cost);   }   int dist[MAXV];   int iter[MAXV];   bool inq[MAXV];   bool SPFA(int S, int T) {     static int q[MAXV];     int f = 0, r = 0;     memset(dist, INF, sizeof(dist));     memset(inq, 0, sizeof(inq));     dist[S] = 0;     q[r++] = S;     inq[S] = true;     while (f != r) {       int x = q[f++];       inq[x] = false;       if (f == MAXV) f = 0;       for (int p = head[x]; ~p; p = edge[p].nxt) {         Edge e = edge[p];         if (e.cap && dist[e.to] > dist[x] + e.cost) {           dist[e.to] = dist[x] + e.cost;           if (!inq[e.to]) {             q[r++] = e.to;             inq[e.to] = true;             if (r == MAXV) r = 0;           }         }       }     }     return dist[T] < INF;   }   int getflow(int x, int lim, int T) {     if (x == T) return lim;     inq[x] = true;     int nowflow = 0, newflow;     for (register int &p = iter[x]; ~p; p = edge[p].nxt) {       register Edge &e = edge[p];       if (!inq[e.to] && e.cap && dist[e.to] == dist[x] + e.cost) {         newflow = getflow(e.to, min(e.cap, lim - nowflow), T);         e.cap -= newflow;         edge[p ^ 1].cap += newflow;         nowflow += newflow;         if (nowflow >= lim) break;       }     }     return nowflow;   }   int mincostmaxflow(int S, int T) {     int nowcost = 0, newflow;     while (SPFA(S, T)) {       for (int i = 0; i < MAXV; i++) iter[i] = head[i];       memset(inq, 0, sizeof(inq));       do {         newflow = getflow(S, INF, T);         nowcost += newflow * dist[T];       } while (newflow);     }     return nowcost;   }   const int MAXN = 210;   const int MAXM = 210;   int S, T, second, TT;   int n1, n2, m, r, b;   int id[MAXM];   int delta[MAXV];   char s[MAXN];   int ans;   int main() {     initedge();     scanf( %d%d%d%d%d , &n1, &n2, &m, &r, &b);     S = 0;     T = n1 + n2 + 1;     scanf( %s , s);     for (int i = 1; i <= n1; i++) {       char c = s[i - 1];       if (c ==  R ) {         addedge2(i, T, INF - 1, 0);         delta[i] -= 1;         delta[T] += 1;       }       if (c ==  B ) {         addedge2(S, i, INF - 1, 0);         delta[S] -= 1;         delta[i] += 1;       }       if (c ==  U ) {         addedge2(S, i, INF - 0, 0);         addedge2(i, T, INF - 0, 0);       }     }     scanf( %s , s);     for (int i = 1; i <= n2; i++) {       char c = s[i - 1];       if (c ==  B ) {         addedge2(n1 + i, T, INF - 1, 0);         delta[n1 + i] -= 1;         delta[T] += 1;       }       if (c ==  R ) {         addedge2(S, n1 + i, INF - 1, 0);         delta[S] -= 1;         delta[n1 + i] += 1;       }       if (c ==  U ) {         addedge2(S, n1 + i, INF - 0, 0);         addedge2(n1 + i, T, INF - 0, 0);       }     }     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       id[i] = cnt;       addedge2(x, n1 + y, 1 - 0, b);       addedge2(n1 + y, x, 1 - 0, r);     }     addedge2(T, S, INF - 0, 0);     second = n1 + n2 + 2;     TT = n1 + n2 + 3;     int sum = 0;     for (int i = S; i <= T; i++) {       if (delta[i] > 0) addedge2(second, i, delta[i], 0), sum += delta[i];       if (delta[i] < 0) addedge2(i, TT, -delta[i], 0);     }     ans = mincostmaxflow(second, TT);     sum = 0;     for (int p = head[second]; ~p; p = edge[p].nxt) sum += edge[p].cap;     if (!sum) {       printf( %d n , ans);       for (int i = 0; i < m; i++) {         if (edge[id[i]].cap == 0)           putchar( B );         else if (edge[id[i] + 2].cap == 0)           putchar( R );         else           putchar( U );       }       putchar(  n );     } else       printf( -1 n );     return 0;   }