#include <bits/stdc++.h>
using namespace std;
const int maxn = 450;
const int maxm = 3e6 + 100;
const long long oo = 1e15;
struct Edges {
  int to, next;
  long long f;
  long long c;
} es[maxm];
int head[maxn] = {0};
int chead[maxn] = {0};
int tp = 1;
void adde(int a, int b, long long f, long long c) {
  tp++;
  es[tp].to = b;
  es[tp].next = head[a];
  head[a] = tp;
  es[tp].c = c;
  es[tp].f = f;
}
void new_edge(int a, int b, long long f, long long c) {
  adde(a, b, f, c);
  adde(b, a, 0, -c);
}
long long dis[maxn] = {0};
bool inq[maxn] = {0};
queue<int> Q;
bool spfa(int st, int ed) {
  for (int i = 0; i < maxn; ++i) {
    dis[i] = oo;
  }
  dis[st] = 0;
  Q.push(st);
  while (!Q.empty()) {
    int t = Q.front();
    inq[t] = 0;
    Q.pop();
    for (int e = head[t]; e; e = es[e].next) {
      int to = es[e].to;
      if (es[e].f && dis[to] > dis[t] + es[e].c) {
        dis[to] = dis[t] + es[e].c;
        if (!inq[to]) {
          Q.push(to);
          inq[to] = 1;
        }
      }
    }
  }
  return (dis[ed] != oo);
}
long long ans;
bool mark[maxn] = {0};
long long dfs(int now, int ed, long long mi) {
  if (now == ed || mi == 0) return mi;
  long long ret = 0;
  mark[now] = 1;
  for (int &e = chead[now]; e; e = es[e].next) {
    int to = es[e].to;
    if (!mark[to] && dis[to] == dis[now] + es[e].c) {
      long long f = dfs(to, ed, min(mi, es[e].f));
      es[e].f -= f, es[e ^ 1].f += f, mi -= f, ret += f;
      ans += (long long)es[e].c * f;
      if (mi <= 0) break;
    }
  }
  mark[now] = 0;
  return ret;
}
long long dinic(int st, int ed) {
  long long ret = 0;
  while (spfa(st, ed)) {
    memcpy(chead, head, sizeof chead);
    ret += dfs(st, ed, 0x3f3f3f3f);
  }
  return ret;
}
int n1, n2, m, r, b;
int main() {
  ios::sync_with_stdio(0);
  cin >> n1 >> n2 >> m >> r >> b;
  char c;
  int S = 0, T = n1 + n2 + 2;
  int SS = n1 + n2 + 3, TT = n1 + n2 + 4;
  const int inf = 0x3f3f3f3f;
  int cntS = 0, cntT = 0;
  for (int i = 1; i <= n1; ++i) {
    cin >> c;
    if (c == 'U') {
      new_edge(S, i, inf, 0);
      new_edge(i, T, inf, 0);
    } else if (c == 'R') {
      new_edge(S, i, inf, 0);
      cntS++;
      new_edge(SS, i, 1, 0);
    } else {
      new_edge(i, T, inf, 0);
      cntT++;
      new_edge(i, TT, 1, 0);
    }
  }
  for (int i = 1; i <= n2; ++i) {
    cin >> c;
    if (c == 'U') {
      new_edge(S, i + n1, inf, 0);
      new_edge(i + n1, T, inf, 0);
    } else if (c == 'B') {
      cntS++;
      new_edge(S, i + n1, inf, 0);
      new_edge(SS, i + n1, 1, 0);
    } else {
      cntT++;
      new_edge(i + n1, T, inf, 0);
      new_edge(i + n1, TT, 1, 0);
    }
  }
  new_edge(S, TT, cntS, 0);
  new_edge(SS, T, cntT, 0);
  int st = tp + 1;
  for (int t1, t2, i = 1; i <= m; ++i) {
    cin >> t1 >> t2;
    new_edge(t1, t2 + n1, 1, r);
    new_edge(t2 + n1, t1, 1, b);
  }
  new_edge(T, S, inf, 0);
  int t = dinic(SS, TT);
  if (t == cntS + cntT) {
    cout << ans << endl;
    for (int i = 1; i <= m; ++i) {
      if (es[st].f == 0) {
        cout << 'R';
      } else if (es[st + 2].f == 0) {
        cout << 'B';
      } else {
        cout << 'U';
      }
      st += 4;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}
