#include <bits/stdc++.h>
using namespace std;
namespace Patchouli {
const int N = 414514;
const int inf = 998244353;
char sl[N];
char sr[N];
int deg[N];
int rid[N];
int bid[N];
int s, t, ss, tt;
int head[N], next[N], ver[N], edge[N], cost[N], tot = 1;
int dis[N];
bool vis[N];
int incf[N];
int pre[N];
int maxflow = 0;
int ans = 0;
inline int read() {
  int a = 1, b = 0;
  char t;
  do {
    t = getchar();
    if (t == '-') a = -1;
  } while (t > '9' || t < '0');
  do {
    b = b * 10 - '0' + t;
    t = getchar();
  } while (t >= '0' && t <= '9');
  return a * b;
}
inline void add(int x, int y, int z, int c) {
  next[++tot] = head[x], head[x] = tot, ver[tot] = y, edge[tot] = z,
  cost[tot] = c;
  next[++tot] = head[y], head[y] = tot, ver[tot] = x, edge[tot] = 0,
  cost[tot] = -c;
}
inline bool SPFA() {
  queue<int> q;
  for (int i = 1; i <= tt; ++i) dis[i] = inf;
  q.push(ss);
  vis[ss] = true;
  dis[ss] = 0;
  incf[ss] = inf;
  while (q.size()) {
    int x = q.front();
    q.pop();
    vis[x] = false;
    for (int i = head[x]; i; i = next[i]) {
      if (edge[i] && dis[x] + cost[i] < dis[ver[i]]) {
        pre[ver[i]] = i;
        incf[ver[i]] = min(incf[x], edge[i]);
        dis[ver[i]] = dis[x] + cost[i];
        if (!vis[ver[i]]) vis[ver[i]] = true, q.push(ver[i]);
      }
    }
  }
  return dis[tt] ^ inf;
}
inline void update() {
  int x = tt;
  while (x ^ ss) {
    int i = pre[x];
    edge[i] -= incf[tt];
    edge[i ^ 1] += incf[tt];
    x = ver[i ^ 1];
  }
  maxflow -= incf[tt];
  ans += incf[tt] * dis[tt];
}
int QAQ() {
  int nl = read(), nr = read(), m = read(), r = read(), b = read();
  s = nl + nr + 1;
  t = s + 1;
  ss = t + 1;
  tt = ss + 1;
  add(t, s, inf, 0);
  scanf("%s", sl + 1);
  for (int i = 1; i <= nl; ++i) {
    switch (sl[i]) {
      case 'R':
        add(s, i, inf - 1, 0);
        ++deg[i];
        --deg[s];
        break;
      case 'B':
        add(i, t, inf - 1, 0);
        ++deg[t];
        --deg[i];
        break;
      case 'U':
        add(s, i, inf, 0);
        add(i, t, inf, 0);
        break;
    }
  }
  scanf("%s", sr + 1);
  for (int i = 1; i <= nr; ++i) {
    switch (sr[i]) {
      case 'R':
        add(nl + i, t, inf - 1, 0);
        ++deg[t];
        --deg[nl + i];
        break;
      case 'B':
        add(s, nl + i, inf - 1, 0);
        ++deg[nl + i];
        --deg[s];
        break;
      case 'U':
        add(s, nl + i, inf, 0);
        add(nl + i, t, inf, 0);
        break;
    }
  }
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read();
    add(x, nl + y, 1, r);
    rid[i] = tot;
    add(nl + y, x, 1, b);
    bid[i] = tot;
  }
  for (int i = 1; i <= t; ++i) {
    if (deg[i] > 0) {
      add(ss, i, deg[i], 0);
      maxflow += deg[i];
    } else if (deg[i] < 0) {
      add(i, tt, -deg[i], 0);
    }
  }
  while (SPFA()) update();
  if (maxflow) {
    puts("-1");
  } else {
    printf("%d\n", ans);
    for (int i = 1; i <= m; ++i) {
      if (edge[rid[i]])
        putchar('R');
      else if (edge[bid[i]])
        putchar('B');
      else
        putchar('U');
    }
    putchar('\n');
  }
  return false;
}
}  // namespace Patchouli
int main() { return Patchouli::QAQ(); }
