#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000000;
int n1, n2, xx, yy, m, r, b, Lid[810], Rid[810], idt, S, T, SS, TT, et, be[810],
    lows, erid[331000], ebid[331000], ansc, answ;
char s[810], ans[810];
struct edg {
  int v, c, w, ne;
} e[331000];
inline void adde(int u, int v, int c, int w) {
  e[++et].v = u;
  e[et].c = 0;
  e[et].w = -w;
  e[et].ne = be[v];
  be[v] = et;
  e[++et].v = v;
  e[et].c = c;
  e[et].w = w;
  e[et].ne = be[u];
  be[u] = et;
}
inline void add_edge(int u, int v, int l, int r, int w) {
  lows += l;
  if (l) {
    adde(SS, v, l, 0);
    adde(u, TT, l, 0);
  }
  adde(u, v, r - l, w);
}
int a[810], d[810], lase[810], lasv[810];
queue<int> q;
bool inq[810];
bool spfa() {
  for (int i = 1; i <= idt; i++) d[i] = oo;
  d[SS] = 0;
  a[SS] = oo;
  q.push(SS);
  inq[SS] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = 0;
    for (int i = be[u]; i; i = e[i].ne)
      if (e[i].c && d[u] + e[i].w < d[e[i].v]) {
        d[e[i].v] = d[u] + e[i].w;
        a[e[i].v] = a[u];
        if (e[i].c < a[e[i].v]) a[e[i].v] = e[i].c;
        lase[e[i].v] = i;
        lasv[e[i].v] = u;
        if (!inq[e[i].v]) {
          q.push(e[i].v);
          inq[e[i].v] = 1;
        }
      }
  }
  if (d[TT] == oo) return 0;
  int u = TT;
  while (u != SS) {
    int &i = lase[u];
    e[i].c -= a[TT];
    e[i ^ 1].c += a[TT];
    u = lasv[u];
  }
  return 1;
}
void mcmf() {
  while (spfa()) {
    ansc += a[TT];
    answ += a[TT] * d[TT];
  }
}
int main() {
  scanf("%d%d%d%d%d", &n1, &n2, &m, &r, &b);
  for (int i = 1; i <= n1; i++) Lid[i] = ++idt;
  for (int i = 1; i <= n2; i++) Rid[i] = ++idt;
  S = ++idt;
  T = ++idt;
  SS = ++idt;
  TT = ++idt;
  et = 1;
  add_edge(T, S, 0, oo, 0);
  scanf("%s", s + 1);
  for (int i = 1; i <= n1; i++) {
    if (s[i] == 'R') {
      add_edge(S, Lid[i], 1, oo, 0);
      continue;
    }
    if (s[i] == 'B') {
      add_edge(Lid[i], T, 1, oo, 0);
      continue;
    }
    add_edge(S, Lid[i], 0, oo, 0);
    add_edge(Lid[i], T, 0, oo, 0);
  }
  scanf("%s", s + 1);
  for (int i = 1; i <= n2; i++) {
    if (s[i] == 'B') {
      add_edge(S, Rid[i], 1, oo, 0);
      continue;
    }
    if (s[i] == 'R') {
      add_edge(Rid[i], T, 1, oo, 0);
      continue;
    }
    add_edge(S, Rid[i], 0, oo, 0);
    add_edge(Rid[i], T, 0, oo, 0);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &xx, &yy);
    add_edge(Lid[xx], Rid[yy], 0, 1, r);
    erid[i] = et;
    add_edge(Rid[yy], Lid[xx], 0, 1, b);
    ebid[i] = et;
  }
  mcmf();
  if (ansc != lows) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    if (!e[erid[i]].c && e[ebid[i]].c) {
      ans[i] = 'R';
      continue;
    }
    if (e[erid[i]].c && !e[ebid[i]].c) {
      ans[i] = 'B';
      continue;
    }
    ans[i] = 'U';
  }
  printf("%d\n%s\n", answ, ans + 1);
  return 0;
}
