#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x) {
  x = 0;
  long long fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= fh;
}
namespace MC_Network_Flow {
struct Edge {
  long long f, t, w, p, nxt;
  Edge(long long ff, long long tt, long long ww, long long pp, long long nnxt)
      : f(ff), t(tt), w(ww), p(pp), nxt(nnxt) {}
  Edge() {}
} edge[200005];
long long head[5005], etot = 1;
void add_edge(long long f, long long t, long long w, long long p = 0) {
  Edge tmpe(f, t, w, p, head[f]);
  edge[++etot] = tmpe;
  head[f] = etot;
}
void add_nete(long long f, long long t, long long w, long long p = 0) {
  add_edge(f, t, w, p);
  add_edge(t, f, 0, -p);
}
long long dis[5005], inq[5005];
long long chd[5005], vis[5005];
queue<long long> q;
void reset() {
  Edge rese(0, 0, 0, 0, 0);
  for (long long i = 1; (i << 1) <= etot; ++i) {
    head[edge[i << 1].f] = head[edge[i << 1].t] = 0;
  }
  for (long long i = 2; i <= etot; ++i) edge[i] = rese;
  etot = 1;
}
bool bfs(long long S, long long T) {
  memset(dis, 0x3f, sizeof(dis));
  memset(inq, 0, sizeof(inq));
  q.push(S);
  dis[S] = 0;
  inq[S] = 1;
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (long long i = head[x]; i; i = edge[i].nxt) {
      long long y = edge[i].t;
      if (edge[i].w && dis[y] > dis[x] + edge[i].p) {
        dis[y] = dis[x] + edge[i].p;
        if (!inq[y]) {
          q.push(y);
          inq[y] = 1;
        }
      }
    }
    inq[x] = 0;
  }
  return dis[T] != 0x3f3f3f3f3f3f3f3fll;
}
long long mcst;
long long dfs(long long x, long long f, long long T) {
  if (x == T) return f;
  vis[x] = 1;
  long long g = 0;
  for (long long &i = chd[x]; i; i = edge[i].nxt) {
    long long y = edge[i].t;
    if (edge[i].w && !vis[y] && dis[y] == dis[x] + edge[i].p) {
      long long d = dfs(y, min(edge[i].w, f - g), T);
      mcst += d * edge[i].p;
      edge[i].w -= d;
      edge[i ^ 1].w += d;
      g += d;
      if (f == g) return g;
    }
  }
  vis[x] = 0;
  return g;
}
pair<long long, long long> Dinic(long long S, long long T) {
  long long ret = 0;
  mcst = 0;
  while (bfs(S, T)) {
    memcpy(chd, head, sizeof(head));
    memset(vis, 0, sizeof(vis));
    ret += dfs(S, 0x3f3f3f3f3f3f3f3fll, T);
  }
  return make_pair(ret, mcst);
}
}  // namespace MC_Network_Flow
namespace MC_Lim_Network_Flow {
using MC_Network_Flow::add_nete;
using MC_Network_Flow::Dinic;
using MC_Network_Flow::reset;
struct Edge {
  long long f, t, wl, wr, p;
  Edge(long long ff, long long tt, long long wwl, long long wwr, long long pp)
      : f(ff), t(tt), wl(wwl), wr(wwr), p(pp) {}
  Edge() {}
} edge[200005];
long long rf[200005];
long long etot;
void add_edge(long long f, long long t, long long wl, long long wr,
              long long p = 0) {
  Edge tmpe(f, t, wl, wr, p);
  edge[++etot] = tmpe;
}
long long ifl[5005], ofl[5005];
void clear() {
  Edge rese(0, 0, 0, 0, 0);
  for (long long i = 1; i <= etot; ++i) {
    ifl[edge[i].f] = ofl[edge[i].f] = 0;
    ifl[edge[i].t] = ofl[edge[i].t] = 0;
  }
  for (long long i = 1; i <= etot; ++i) edge[i] = rese;
  etot = 0;
}
long long ans1, ans2;
long long NSTF() {
  long long ret = 0, mx = 0;
  for (long long i = 1; i <= etot; ++i) {
    long long u = edge[i].f, v = edge[i].t, wl = edge[i].wl, wr = edge[i].wr;
    mx = max(mx, max(u, v));
    ret += wl;
    ifl[v] += wl;
    ofl[u] += wl;
    ans1 += wl * edge[i].p;
    add_nete(u, v, wr - wl, edge[i].p);
    rf[i] = MC_Network_Flow::etot - 1;
  }
  long long S = mx + 1, T = S + 1, sm = 0;
  for (long long i = 1; i <= mx; ++i) {
    if (ifl[i] > ofl[i])
      add_nete(S, i, ifl[i] - ofl[i], 0), sm += ifl[i] - ofl[i];
    else
      add_nete(i, T, ofl[i] - ifl[i], 0);
  }
  pair<long long, long long> tmp = Dinic(S, T);
  if (tmp.first != sm) return -1;
  ans2 = tmp.second;
  return 0;
}
long long STMCAF(long long S, long long T) {
  ans1 = ans2 = 0;
  reset();
  add_nete(T, S, 0x3f3f3f3f3f3f3f3fll, 0);
  if (NSTF() == -1) return -1;
  return ans1 + ans2;
}
vector<long long> G[5005];
long long vs[5005];
void dfs(long long x) {
  if (vs[x]) return;
  vs[x] = 1;
  for (auto y : G[x]) {
    dfs(y);
  }
}
bool chk0(long long S, long long T) {
  for (long long i = 1; i <= etot; ++i) G[edge[i].f].push_back(edge[i].t);
  dfs(S);
  return vs[T] == 0;
}
}  // namespace MC_Lim_Network_Flow
using MC_Lim_Network_Flow::add_edge;
using MC_Lim_Network_Flow::chk0;
using MC_Lim_Network_Flow::rf;
using MC_Lim_Network_Flow::STMCAF;
long long n1, n2, m, R, B;
char s1[5005], s2[5005];
signed main() {
  read(n1);
  read(n2);
  read(m);
  read(R);
  read(B);
  scanf("%s%s", s1 + 1, s2 + 1);
  long long S = n1 + n2 + 1, T = S + 1;
  for (long long i = 1, u, v; i <= m; ++i) {
    read(u);
    read(v);
    add_edge(u, v + n1, 0, 1, R);
    add_edge(v + n1, u, 0, 1, B);
  }
  for (long long i = 1; i <= n1; ++i) {
    if (s1[i] == 'R') {
      add_edge(S, i, 1, 0x3f3f3f3f3f3f3f3fll, 0);
    }
    if (s1[i] == 'B') {
      add_edge(i, T, 1, 0x3f3f3f3f3f3f3f3fll, 0);
    }
    if (s1[i] == 'U') {
      add_edge(S, i, 0, 0x3f3f3f3f3f3f3f3fll, 0);
      add_edge(i, T, 0, 0x3f3f3f3f3f3f3f3fll, 0);
    }
  }
  for (long long i = 1; i <= n2; ++i) {
    if (s2[i] == 'B') {
      add_edge(S, i + n1, 1, 0x3f3f3f3f3f3f3f3fll, 0);
    }
    if (s2[i] == 'R') {
      add_edge(i + n1, T, 1, 0x3f3f3f3f3f3f3f3fll, 0);
    }
    if (s2[i] == 'U') {
      add_edge(S, i + n1, 0, 0x3f3f3f3f3f3f3f3fll, 0);
      add_edge(i + n1, T, 0, 0x3f3f3f3f3f3f3f3fll, 0);
    }
  }
  if (chk0(S, T)) {
    puts("-1");
    return 0;
  }
  long long ans = STMCAF(S, T);
  if (ans == -1) {
    puts("-1");
    return 0;
  }
  printf("%lld\n", ans);
  for (long long i = 1; i <= m; ++i) {
    if (MC_Network_Flow::edge[rf[(i << 1) - 1]].w == 0) {
      putchar('R');
    } else {
      if (MC_Network_Flow::edge[rf[(i << 1)]].w == 0) {
        putchar('B');
      } else
        putchar('U');
    }
  }
  return 0;
}
