#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct in {
  int n;
  in() {}
  in(int n_) : n(n_) {}
  template <class T>
  operator T() {
    T ret;
    cin >> ret;
    return ret;
  }
  template <class T>
  operator vector<T>() {
    vector<T> ret(n);
    for (int i = 0; i < n; i++) cin >> ret[i];
    return ret;
  }
};
struct SetupIO {
  SetupIO() {
    cin.tie(nullptr), ios::sync_with_stdio(false),
        cout << fixed << setprecision(20);
  }
} setup_io;
signed main() {
  int n = in(), m = in();
  vector<Int> D = in(n);
  struct Edge {
    Int to, idx;
  };
  vector<vector<Edge>> g(n);
  for (int i = 0; i < m; i++) {
    int u = in(), v = in();
    u--, v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  vector<Int> ord(n);
  for (Int i = 0, max_i = (n); i < max_i; i++) ord[i] = i;
  sort(ord.begin(), ord.end(), [&D](Int i, Int j) { return D[i] < D[j]; });
  vector<Int> ans(m, 1e9), color(n, -1);
  for (Int k = 0, max_i = (n); k < max_i; k++) {
    Int i = ord[k];
    bool ok = false;
    for (Edge& e : g[i]) {
      if (D[e.to] <= D[i]) {
        if (color[e.to] == -1) {
          color[e.to] = 0, color[i] = 1;
        } else {
          color[i] = !color[e.to];
        }
        ans[e.idx] = D[i];
        ok = true;
        break;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  };
  for (Int x : color) {
    assert(0 <= x && x <= 1);
    cout << (x ? 'B' : 'W');
  }
  cout << endl;
  for (Int x : ans) cout << x << endl;
}
