#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<vector<ll>> net;
vector<ll> tgt, color;
void coloring(ll v, ll par) {
  if (par == -1) {
    color.at(v) = 1;
  } else {
    color.at(v) = color.at(par) * -1;
  }
  for (ll nxt : net.at(v)) {
    if (tgt.at(nxt) == v || tgt.at(v) == nxt) {
      if (color.at(nxt) == 0) {
        coloring(nxt, v);
      }
    }
  }
}
void solve(long long N, long long M, std::vector<long long> D,
           std::vector<long long> U, std::vector<long long> V) {
  net.resize(N);
  for (ll i = 0; i < (M); ++i) {
    U.at(i)--;
    V.at(i)--;
    net.at(U.at(i)).push_back(V.at(i));
    net.at(V.at(i)).push_back(U.at(i));
  }
  tgt.resize(N);
  for (ll i = 0; i < (N); ++i) {
    ll min_idx = net.at(i).front();
    for (ll j : net.at(i)) {
      if (D.at(min_idx) > D.at(j)) {
        min_idx = j;
      }
    }
    tgt.at(i) = min_idx;
  }
  color.resize(N);
  fill(color.begin(), color.end(), 0);
  for (ll i = 0; i < (N); ++i) {
    if (color.at(i) != 0) {
      continue;
    }
    coloring(i, -1);
  }
  for (ll i = 0; i < (N); ++i) {
    if (color.at(i) == 1) {
      cout << 'W';
    } else {
      assert(color.at(i) == -1);
      cout << 'B';
    }
  }
  cout << endl;
  for (ll i = 0; i < (M); ++i) {
    ll x = U.at(i);
    ll y = V.at(i);
    if (tgt.at(x) == y) {
      cout << D.at(x) << endl;
    } else if (tgt.at(y) == x) {
      cout << D.at(y) << endl;
    } else {
      cout << 1000000000 << endl;
    }
  }
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> D(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &D[i]);
  }
  std::vector<long long> U(M);
  std::vector<long long> V(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &U[i]);
    scanf("%lld", &V[i]);
  }
  solve(N, M, std::move(D), std::move(U), std::move(V));
  return 0;
}
