#include <bits/stdc++.h>
using namespace std;
int main() {
  const int INF = 1e9;
  int N, M;
  cin >> N >> M;
  vector<int> D(N);
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }
  vector<pair<int, int>> E;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    if (u > v) swap(u, v);
    E.emplace_back(u, v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int d_min = *min_element(D.begin(), D.end());
  if (count(D.begin(), D.end(), d_min) < 2) {
    cout << -1 << endl;
    return 0;
  }
  priority_queue<pair<int, int>> pq;
  vector<bool> visited(N);
  int s = min_element(D.begin(), D.end()) - D.begin();
  pq.emplace(D[s], s);
  vector<int> W(M, -1);
  string C(N, '?');
  C[s] = 'W';
  while (!pq.empty()) {
    int v = pq.top().second;
    pq.pop();
    visited[v] = true;
    for (auto v_ : G[v]) {
      int idx =
          lower_bound(E.begin(), E.end(), make_pair(min(v, v_), max(v, v_))) -
          E.begin();
      cerr << v << " " << v_ << " " << idx << endl;
      if (visited[v_]) {
        if (W[idx] < 0) W[idx] = INF;
      } else {
        pq.emplace(-D[v_], v_);
        visited[v_] = true;
        if (D[v_] > D[v]) {
          C[v_] = C[v];
          W[idx] = D[v_] - D[v];
        } else {
          if (C[v] == 'W')
            C[v_] = 'B';
          else
            C[v_] = 'W';
          W[idx] = D[v_];
        }
      }
    }
  }
  cout << C << endl;
  for (auto w : W) {
    cout << w << "\n";
  }
}
