#include <bits/stdc++.h>   using namespace std;   using namespace std;   int n1, n2, m, R, B, mxn, E[10005], nxt[10005], hd[10005], to[10005],       adj[10005], cost[10005], cur[10005], dis[10005], D[10005], second, T, s, t,       tot = 0, mnc = 0;   bool vis[10005], inq[10005];   char s1[10005], s2[10005];   inline void add(int u, int v, int w, int f) {     nxt[tot] = hd[u];     hd[u] = tot;     to[tot] = v;     adj[tot] = w;     cost[tot] = f;     ++tot;     nxt[tot] = hd[v];     hd[v] = tot;     to[tot] = u;     adj[tot] = 0;     cost[tot] = -f;     ++tot;     return;   }   inline bool spfa() {     for (int i = second; i <= T; ++i) dis[i] = 0x3f3f3f3f, inq[i] = 0;     queue<int> q;     q.push(T);     dis[T] = 0;     inq[T] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       inq[u] = 0;       for (int i = hd[u]; ~i; i = nxt[i])         if (adj[i ^ 1] && dis[to[i]] > dis[u] - cost[i]) {           dis[to[i]] = dis[u] - cost[i];           if (!inq[to[i]]) q.push(to[i]), inq[to[i]] = 1;         }     }     return dis[second] < 0x3f3f3f3f;   }   inline int dfs(int u, int low) {     vis[u] = 1;     if (u == T) return low;     int sum = 0, gt;     for (int &i = cur[u]; ~i; i = nxt[i])       if (adj[i] > 0 && dis[to[i]] == dis[u] - cost[i] && !vis[to[i]]) {         gt = dfs(to[i], min(low - sum, adj[i]));         if (gt) {           adj[i] -= gt;           adj[i ^ 1] += gt;           sum += gt;           mnc += gt * cost[i];         }         if (sum == low) break;       }     return sum;   }   inline int dinic() {     int mxf = 0;     while (spfa()) {       vis[T] = 1;       while (vis[T]) {         for (int i = second; i <= T; ++i) cur[i] = hd[i], vis[i] = 0;         mxf += dfs(second, 0x3f3f3f3f);       }     }     return mxf;   }   int main() {     int u, v;     scanf( %d%d%d%d%d%s%s , &n1, &n2, &m, &R, &B, s1 + 1, s2 + 1);     memset(hd, -1, sizeof(hd));     second = 1;     s = 2;     t = 3 + n1 + n2;     T = 4 + n1 + n2;     for (int i = 1; i <= n1; ++i) {       if (s1[i] ==  R ) {         --D[s];         ++D[i + 2];         add(s, i + 2, 0x3f3f3f3f, 0);       }       if (s1[i] ==  B ) {         --D[i + 2];         ++D[t];         add(i + 2, t, 0x3f3f3f3f, 0);       }       if (s1[i] ==  U ) {         add(s, i + 2, 0x3f3f3f3f, 0), add(i + 2, t, 0x3f3f3f3f, 0);       }     }     for (int i = 1; i <= n2; ++i) {       if (s2[i] ==  R ) {         --D[i + 2 + n1];         ++D[t];         add(i + 2 + n1, t, 0x3f3f3f3f, 0);       }       if (s2[i] ==  B ) {         ++D[i + 2 + n1];         --D[s];         add(s, i + 2 + n1, 0x3f3f3f3f, 0);       }       if (s2[i] ==  U ) {         add(s, i + 2 + n1, 0x3f3f3f3f, 0), add(i + 2 + n1, t, 0x3f3f3f3f, 0);       }     }     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &u, &v);       E[i] = tot;       add(u + 2, v + 2 + n1, 1, R);       add(v + 2 + n1, u + 2, 1, B);     }     for (int i = s; i <= t; ++i) {       if (D[i] < 0) add(i, T, -D[i], 0);       if (D[i] > 0) add(second, i, D[i], 0), mxn += D[i];     }     add(t, s, 0x3f3f3f3f, 0);     if (dinic() < mxn) {       puts( -1 );       return 0;     }     printf( %d n , mnc);     for (int i = 1; i <= m; ++i) {       if (!adj[E[i]])         putchar( R );       else if (!adj[E[i] + 2])         putchar( B );       else         putchar( U );     }     putchar(  n );     return 0;   }