#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> D(N);
  for (int i = 0, i_len = int(N); i < i_len; ++i) cin >> D[i];
  vector<vector<pair<int, int>>> graph(N);
  for (int i = 0, i_len = int(M); i < i_len; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(pair<int, int>(v, i));
    graph[v].push_back(pair<int, int>(u, i));
  }
  const int INF = 1e9;
  string ans(N, 'W');
  vector<bool> used(N, false);
  vector<int> C(M, INF);
  vector<int> leaf;
  function<void(int)> dfs = [&](int u) {
    bool res = false;
    used[u] = true;
    for (auto v : graph[u])
      if (!used[v.first] && D[u] >= D[v.first]) {
        C[v.second] = D[u];
        ans[v.first] = (ans[u] == 'W' ? 'B' : 'W');
        dfs(v.first);
        res = true;
      }
  };
  for (int i = 0, i_len = int(N); i < i_len; ++i) {
    dfs(i);
    used[i] = false;
  }
  for (int u = 0, u_len = int(N); u < u_len; ++u) {
    bool ok = false;
    for (auto v : graph[u]) {
      if (C[v.second] == D[u]) ok = true;
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  for (int i = 0, i_len = int(M); i < i_len; ++i) cout << C[i] << endl;
}
