#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> D(N);
  for (int i = 0; i < N; ++i) cin >> D[i];
  vector<vector<pair<int, int>>> G(N);
  for (int i = 0; i < M; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    G[u].emplace_back(v, i);
    G[v].emplace_back(u, i);
  }
  int Min = INF + 1, s, ok = 0;
  for (int i = 0; i < N; ++i)
    if (D[i] < Min) {
      s = i;
      Min = D[i];
    }
  vector<int> used(N, 0), cost(M, INF), color(N, 0);
  queue<int> que;
  used[s] = 1;
  que.emplace(s);
  for (auto p : G[s])
    if (D[p.first] == Min) {
      used[p.first] = 1;
      que.emplace(p.first);
      cost[p.second] = Min;
      color[p.first] = 1;
      ok = 1;
    }
  if (!ok) {
    cout << -1 << '\n';
    return 0;
  }
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (auto q : G[p]) {
      if (used[q.first]) continue;
      used[q.first] = 1;
      que.emplace(q.first);
      cost[q.second] = D[q.first];
      color[q.first] = color[p] ^ 1;
    }
  }
  for (int i = 0; i < N; ++i) cout << (color[i] ? 'B' : 'W');
  cout << '\n';
  for (int i = 0; i < M; ++i) cout << cost[i] << '\n';
}
