#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct PriQue {
  const ll INF = 4 * (ll)1e18;
  vector<pair<ll, int>> data;
  const int n;
  PriQue(int siz) : n(siz), data(2 * siz, {INF, -1}) { data[0] = {-INF, -1}; }
  void push(int i, ll v) {
    data[i + n] = {v, (v >= INF ? -1 : i)};
    for (i += n; i > 1; i >>= 1) data[i >> 1] = min(data[i], data[i ^ 1]);
  }
  void decKey(int i, ll v) {
    for (int j = i + n; data[j].first > v; j >>= 1) data[j] = {v, i};
  }
  pair<ll, int> pop() {
    auto res = data[1];
    push(res.second, INF);
    return res;
  }
};
class MinCostCirc {
 private:
  struct Edge {
    const int t;
    const ll ru, c;
    ll u = 0;
    Edge(int tar, ll cap, ll cost) : t(tar), ru(cap), c(cost) {}
  };
  const ll INF = (ll)1e18;
  const int n;
  vector<Edge> edges;
  vector<vector<int>> g;
  vector<ll> p;
  ll pushFlow(int ei, ll f) {
    edges[ei].u -= f;
    edges[ei ^ 1].u += f;
    return edges[ei].c * f;
  }
  vector<int> djikstra(PriQue& que, vector<ll>& dist) {
    vector<int> pre(p.size(), -1);
    while (true) {
      int i = que.pop().second;
      if (i == -1) return pre;
      for (int ei : g[i]) {
        Edge& ed = edges[ei];
        ll off = dist[i] + (ed.c + p[i] - p[ed.t]);
        if (ed.u && off < dist[ed.t]) {
          pre[ed.t] = ei;
          dist[ed.t] = off;
          que.decKey(ed.t, off);
        }
      }
    }
  }
  vector<int> updatePotentials(int s) {
    PriQue que(n);
    vector<ll> dist(n, INF);
    dist[s] = 0;
    que.decKey(s, 0);
    auto res = djikstra(que, dist);
    for (int i = 0; i < n; ++i) p[i] += dist[i];
    return res;
  }
  void fixPotentials() {
    PriQue que(n);
    vector<ll> dist(n);
    for (int i = 0; i < n; ++i) {
      dist[i] = -p[i];
      que.decKey(i, dist[i]);
    }
    djikstra(que, dist);
    for (int i = 0; i < n; ++i) p[i] += dist[i];
  }

 public:
  MinCostCirc(int nc) : n(nc), g(nc), p(nc, 0) {}
  void addEdge(int s, int t, ll u, ll c) {
    int i = edges.size();
    edges.emplace_back(t, u, c);
    edges.emplace_back(s, 0, -c);
    g[s].push_back(i);
    g[t].push_back(i ^ 1);
  }
  ll solve() {
    ll res = 0;
    for (ll h = 1ll << 62; h > 0; h >>= 1) {
      for (int ei = 0; ei < edges.size(); ++ei) {
        Edge& ed = edges[ei];
        if (!(ed.ru & h)) continue;
        if (ed.u)
          ed.u += h;
        else {
          int s = edges[ei ^ 1].t;
          auto bp = updatePotentials(ed.t);
          ed.u += h;
          if (ed.c + p[s] - p[ed.t] < 0) {
            bp[ed.t] = ei;
            for (int i = s; ed.u > 0;) {
              res += pushFlow(bp[i], h);
              i = edges[bp[i] ^ 1].t;
            }
          }
          fixPotentials();
        }
      }
    }
    return res;
  }
  ll flow(int ei) const { return edges[2 * ei ^ 1].u; }
};
const int INF = 1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n1, n2, m;
  ll c1, c2;
  cin >> n1 >> n2 >> m >> c1 >> c2;
  MinCostCirc mcc(n1 + n2 + 1);
  int so = n1 + n2;
  string le, ri;
  cin >> le >> ri;
  for (int j = 0; j < m; ++j) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    mcc.addEdge(a, n1 + b, 1, c2);
    mcc.addEdge(n1 + b, a, 1, c1);
  }
  ll cc = 0;
  for (int i = 0; i < n1; ++i) {
    if (le[i] == 'R') {
      mcc.addEdge(i, so, 1, -INF);
      mcc.addEdge(i, so, INF, 0);
      ++cc;
    } else if (le[i] == 'B') {
      mcc.addEdge(so, i, 1, -INF);
      mcc.addEdge(so, i, INF, 0);
      ++cc;
    } else {
      mcc.addEdge(i, so, INF, 0);
      mcc.addEdge(so, i, INF, 0);
    }
  }
  for (int i = 0; i < n2; ++i) {
    if (ri[i] == 'B') {
      mcc.addEdge(n1 + i, so, 1, -INF);
      mcc.addEdge(n1 + i, so, INF, 0);
      ++cc;
    } else if (ri[i] == 'R') {
      mcc.addEdge(so, n1 + i, 1, -INF);
      mcc.addEdge(so, n1 + i, INF, 0);
      ++cc;
    } else {
      mcc.addEdge(n1 + i, so, INF, 0);
      mcc.addEdge(so, n1 + i, INF, 0);
    }
  }
  ll cost = cc * INF + mcc.solve();
  if (cost >= INF) {
    cout << -1 << '\n';
  } else {
    cout << cost << '\n';
    for (int i = 0; i < m; ++i) {
      int d = mcc.flow(2 * i) - mcc.flow(2 * i + 1);
      if (d == 1)
        cout << 'B';
      else if (d == 0)
        cout << 'U';
      else
        cout << 'R';
    }
    cout << '\n';
  }
}
