#include <bits/stdc++.h>
using namespace std;
int n, m;
struct edge {
  int from;
  int to;
  long long w;
  int cap;
};
edge edges[10000];
vector<vector<int>> adj;
int add_edge(int from, int to, long long w, int cap, int cap2 = 0) {
  int idx = m;
  edges[idx] = {from, to, w, cap};
  edges[idx + 1] = {to, from, -w, cap2};
  adj[from].push_back(idx);
  adj[to].push_back(idx + 1);
  m += 2;
  return idx;
}
vector<int> find_neg_cycle() {
  vector<long long> dp(n);
  vector<int> pred(n, -1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (edges[j].cap == 0) continue;
      int from = edges[j].from, to = edges[j].to, w = edges[j].w;
      if (dp[from] + w < dp[to]) {
        dp[to] = dp[from] + w;
        pred[to] = j;
      }
    }
  }
  vector<int> ind(n);
  for (int i = 0; i < n; i++) {
    if (pred[i] != -1) {
      ind[edges[pred[i]].from]++;
    }
  }
  vector<int> q;
  for (int i = 0; i < n; i++) {
    if (ind[i] == 0) {
      q.push_back(i);
    }
  }
  for (int i = 0; i < q.size(); i++) {
    int x = q[i];
    if (pred[x] == -1) continue;
    int y = edges[pred[x]].from;
    ind[y]--;
    if (ind[y] == 0) {
      q.push_back(y);
    }
  }
  vector<int> ret;
  for (int i = 0; i < n; i++) {
    if (ind[i]) {
      while (ind[i] >= 1) {
        if (ind[i] != 1) {
          for (int x : ind) cout << x << " ";
          cout << endl;
          exit(0);
        }
        assert(ind[i] == 1);
        ind[i] -= 1;
        ret.push_back(pred[i]);
        i = edges[pred[i]].from;
      }
      break;
    }
  }
  return ret;
}
long long min_circ() {
  long long ret = 0;
  while (true) {
    auto cyc = find_neg_cycle();
    int cyc_w = 0;
    if (cyc.size() == 0) {
      break;
    }
    for (int j : cyc) {
      int j_opp = (j ^ 1);
      edges[j].cap--;
      edges[j_opp].cap++;
      cyc_w += edges[j].w;
    }
    assert(cyc_w < 0);
    ret += cyc_w;
  }
  return ret;
}
int main() {
  int n1, n2, M, r, b;
  cin >> n1 >> n2 >> M >> r >> b;
  n = n1 + n2 + 1;
  adj = vector<vector<int>>(n);
  m = 0;
  string s;
  cin >> s;
  int free = 0;
  long long inf = 201 * 201 * 2;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'R') {
      add_edge(0, i + 1, -inf, 1);
      add_edge(0, i + 1, 0, inf);
    } else if (s[i] == 'B') {
      add_edge(i + 1, 0, -inf, 1);
      add_edge(i + 1, 0, 0, inf);
    } else {
      free++;
      add_edge(0, i + 1, 0, inf, inf);
    }
  }
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      add_edge(0, i + 1 + n1, -inf, 1);
      add_edge(0, i + 1 + n1, 0, inf);
    } else if (s[i] == 'R') {
      add_edge(i + 1 + n1, 0, -inf, 1);
      add_edge(i + 1 + n1, 0, 0, inf);
    } else {
      free++;
      add_edge(0, i + 1 + n1, 0, inf, inf);
    }
  }
  vector<int> mid_edges;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    y += n1;
    mid_edges.push_back(add_edge(x, y, r, 1));
    mid_edges.push_back(add_edge(y, x, b, 1));
  }
  long long ans = min_circ() + inf * (n1 + n2 - free);
  if (ans >= inf) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  for (int i = 0; i < M; i++) {
    if (edges[mid_edges[i * 2]].cap == 0) {
      cout << 'R';
    } else if (edges[mid_edges[i * 2 + 1]].cap == 0) {
      cout << 'B';
    } else {
      cout << 'U';
    }
  }
  cout << endl;
}
