#include <bits/stdc++.h>
using namespace std;
typedef double T;
const T eps = 1e-8, inf = 1 / .0;
struct LPSolver {
  int m, n;
  vector<int> N, B;
  vector<vector<T> > D;
  LPSolver(const vector<vector<T> >& A, const vector<T>& b, const vector<T>& c)
      : m((int)(b).size()),
        n((int)(c).size()),
        N(n + 1),
        B(m),
        D(m + 2, vector<T>(n + 2)) {
    for (int i = 0; i < (m); ++i)
      for (int j = 0; j < (n); ++j) D[i][j] = A[i][j];
    for (int i = 0; i < (m); ++i) {
      B[i] = n + i;
      D[i][n] = -1;
      D[i][n + 1] = b[i];
    }
    for (int j = 0; j < (n); ++j) {
      N[j] = j;
      D[m][j] = -c[j];
    }
    N[n] = -1;
    D[m + 1][n] = 1;
  }
  void pivot(int r, int s) {
    T *a = D[r].data(), inv = 1 / a[s];
    for (int i = 0; i < (m + 2); ++i)
      if (i != r && abs(D[i][s]) > eps) {
        T *b = D[i].data(), inv2 = b[s] * inv;
        for (int j = 0; j < (n + 2); ++j) b[j] -= a[j] * inv2;
        b[s] = a[s] * inv2;
      }
    for (int j = 0; j < (n + 2); ++j)
      if (j != s) D[r][j] *= inv;
    for (int i = 0; i < (m + 2); ++i)
      if (i != r) D[i][s] *= -inv;
    D[r][s] = inv;
    swap(B[r], N[s]);
  }
  bool simplex(int phase) {
    int x = m + phase - 1;
    for (;;) {
      int s = -1;
      for (int j = 0; j < (n + 1); ++j)
        if (N[j] != -phase)
          if (s == -1 || make_pair(D[x][j], N[j]) < make_pair(D[x][s], N[s]))
            s = j;
      if (D[x][s] >= -eps) return true;
      int r = -1;
      for (int i = 0; i < (m); ++i) {
        if (D[i][s] <= eps) continue;
        if (r == -1 || make_pair(D[i][n + 1] / D[i][s], B[i]) <
                           make_pair(D[r][n + 1] / D[r][s], B[r]))
          r = i;
      }
      if (r == -1) return false;
      pivot(r, s);
    }
  }
  T solve(vector<T>& x) {
    int r = 0;
    for (int i = 1; i < (m); ++i)
      if (D[i][n + 1] < D[r][n + 1]) r = i;
    if (D[r][n + 1] < -eps) {
      pivot(r, n);
      if (!simplex(2) || D[m + 1][n + 1] < -eps) return -inf;
      for (int i = 0; i < (m); ++i)
        if (B[i] == -1) {
          int s = 0;
          for (int j = 1; j < (n + 1); ++j)
            if (s == -1 || make_pair(D[i][j], N[j]) < make_pair(D[i][s], N[s]))
              s = j;
          pivot(i, s);
        }
    }
    bool ok = simplex(1);
    x = vector<T>(n);
    for (int i = 0; i < (m); ++i)
      if (B[i] < n) x[B[i]] = D[i][n + 1];
    return ok ? D[m][n + 1] : inf;
  }
};
void bad(string s = "-1") {
  cout << s << endl;
  exit(0);
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int n1, n2, m, cost_r, cost_b;
  cin >> n1 >> n2 >> m >> cost_r >> cost_b;
  int n = n1 + n2;
  string s1, s2;
  cin >> s1 >> s2;
  string s = s1 + s2;
  vector<vector<int> > adj(n);
  for (int i = 0; i < (m); ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    v += n1;
    adj[u].push_back(i);
    adj[v].push_back(i);
  }
  auto red = [&](int i) { return i; };
  auto blue = [&](int i) { return i + m; };
  vector<vector<T> > A;
  vector<T> b;
  for (int i = 0; i < (m); ++i) {
    vector<T> row(2 * m, 0);
    row[red(i)] = 1;
    row[blue(i)] = 1;
    A.emplace_back(row);
    b.emplace_back(1);
  }
  for (int i = 0; i < (n); ++i) {
    if (s[i] == 'U') {
    } else if (s[i] == 'R') {
      vector<T> row(2 * m, 0);
      for (int x : adj[i]) {
        row[red(x)] = -1;
        row[blue(x)] = 1;
      }
      A.emplace_back(row);
      b.emplace_back(-1);
    } else if (s[i] == 'B') {
      vector<T> row(2 * m, 0);
      for (int x : adj[i]) {
        row[red(x)] = 1;
        row[blue(x)] = -1;
      }
      A.emplace_back(row);
      b.emplace_back(-1);
    } else
      assert(false);
  }
  vector<T> c(2 * m, 0);
  for (int i = 0; i < (m); ++i) {
    c[red(i)] = -cost_r - 10 * eps * i;
    c[blue(i)] = -cost_b + 10 * eps * i;
  }
  LPSolver simplex(A, b, c);
  vector<T> xx;
  auto ans = simplex.solve(xx);
  if (ans == -inf) bad();
  long long ans2 = 0;
  for (int i = 0; i < (m); ++i) {
    if (xx[red(i)] > 0.5)
      ans2 += cost_r;
    else if (xx[blue(i)] > 0.5)
      ans2 += cost_b;
  }
  cout << ans2 << endl;
  for (int i = 0; i < (m); ++i) {
    if (xx[red(i)] > 0.5)
      cout << 'R';
    else if (xx[blue(i)] > 0.5)
      cout << 'B';
    else
      cout << 'U';
  }
  cout << endl;
}
