#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 1e9;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int to[N], ww[N], cc[N], h[N], nxt[N], n1, n2, m, r, b, n, s, t, ss, tt, dis[N],
    cur[N], cost, u[N], v[N];
char s1[N], s2[N];
bool vis[N];
void adde(int u, int v, int w, int c) {
  static int tt = 1;
  to[++tt] = v;
  ww[tt] = w;
  cc[tt] = c;
  nxt[tt] = h[u];
  h[u] = tt;
  to[++tt] = u;
  cc[tt] = -c;
  nxt[tt] = h[v];
  h[v] = tt;
}
void adde1(int u, int v) {
  adde(u, v, inf, 0);
  adde(s, v, 1, 0);
  adde(u, t, 1, 0);
}
bool spfa() {
  memset(dis, 0x3f, 4 * (t + 1));
  memset(vis, 0, t + 1);
  deque<int> q;
  q.push_back(s);
  dis[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    vis[u] = 0;
    for (int i = h[u], v; v = to[i], i; i = nxt[i])
      if (ww[i] && dis[v] > dis[u] + cc[i]) {
        dis[v] = dis[u] + cc[i];
        if (!vis[v]) vis[v] = 1, cc[i] < 0 ? q.push_front(v) : q.push_back(v);
      }
  }
  return dis[t] < inf;
}
int dfs(int u, int flow) {
  if (u == t) return flow;
  int ret = 0;
  vis[u] = 1;
  for (int &i = cur[u], v; v = to[i], i; i = nxt[i])
    if (dis[v] == dis[u] + cc[i] && !vis[v] && ww[i]) {
      int d = dfs(v, min(flow, ww[i]));
      ww[i] -= d;
      ww[i ^ 1] += d;
      ret += d;
      flow -= d;
      cost += cc[i] * d;
      if (!flow) {
        vis[u] = 0;
        break;
      }
    }
  return ret;
}
int main() {
  cin >> n1 >> n2 >> m >> r >> b;
  n = n1 + n2;
  ss = n + 1;
  tt = ss + 1;
  t = tt + 1;
  scanf("%s%s", s1 + 1, s2 + 1);
  for (int i = 1; i <= m; i++) {
    u[i] = gi();
    v[i] = gi() + n1;
    adde(u[i], v[i], 1, r);
    adde(v[i], u[i], 1, b);
  }
  for (int i = 1; i <= n1; i++)
    if (s1[i] == 'R')
      adde1(ss, i);
    else if (s1[i] == 'B')
      adde1(i, tt);
    else
      adde(ss, i, inf, 0), adde(i, tt, inf, 0);
  for (int i = 1; i <= n2; i++)
    if (s2[i] == 'R')
      adde1(i + n1, tt);
    else if (s2[i] == 'B')
      adde1(ss, i + n1);
    else
      adde(ss, i + n1, inf, 0), adde(i + n1, tt, inf, 0);
  adde(tt, ss, inf, 0);
  while (spfa()) memcpy(cur, h, 4 * (t + 1)), dfs(s, inf);
  for (int i = h[s]; i; i = nxt[i])
    if (ww[i]) return cout << -1, 0;
  cout << cost << '\n';
  for (int i = 1; i <= m; i++) {
    if (!ww[4 * i - 2] && ww[4 * i])
      putchar('R');
    else if (ww[4 * i - 2] && !ww[4 * i])
      putchar('B');
    else
      putchar('U');
  }
  return 0;
}
