#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> D(N);
  for (int &d : D) cin >> d;
  vector<vector<int>> E(N), EI(N);
  for (int i = 0; i < M; i++) {
    int U, V;
    cin >> U >> V;
    U--, V--;
    E[U].push_back(V);
    EI[U].push_back(i);
    E[V].push_back(U);
    EI[V].push_back(i);
  }
  vector<pair<int, int>> T(N);
  for (int i = 0; i < N; i++) T[i] = make_pair(D[i], i);
  sort(T.begin(), T.end());
  string S(N, '.');
  vector<int> W(M);
  for (int i = 0; i < N; i++) {
    int p = T[i].second;
    bool ok = false;
    for (int e = 0; e < (int)E[p].size(); e++) {
      if (S[E[p][e]] != '.') {
        if (S[p] == '.') S[p] = 'W';
        if (S[E[p][e]] != S[p]) W[EI[p][e]] = D[p];
        if (W[EI[p][e]] == 0) W[EI[p][e]] = D[p] - D[E[p][e]];
        ok = true;
      } else if (D[E[p][e]] == D[p]) {
        if (S[p] == '.') S[p] = 'W';
        if (S[p] == 'W')
          S[E[p][e]] = 'B';
        else
          S[E[p][e]] = 'W';
        W[EI[p][e]] = D[p];
        ok = true;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < M; i++)
    if (W[i] == 0) W[i] = 1000000000;
  cout << S << endl;
  for (int w : W) cout << w << endl;
}
