#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
int MAX = 1000000000;
int N, M;
int D[112345];
int U[112345], V[112345];
vector<pii> g[112345];
int col[112345];
int ans[212345];
int main() {
  cin >> N >> M;
  for (int i = (0); i < (N); ++i) scanf("%d", D + i);
  for (int i = (0); i < (M); ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u;
    --v;
    g[u].push_back(pii(v, i));
    g[v].push_back(pii(u, i));
  }
  vector<int> ord(N);
  for (int i = (0); i < (N); ++i) ord[i] = i;
  sort(begin(ord), end(ord), [&](int a, int b) { return D[a] < D[b]; });
  memset(col, -1, sizeof(col));
  memset(ans, -1, sizeof(ans));
  for (int i : ord) {
    for (pii cur : g[i]) {
      int v = cur.second;
      if (D[i] == D[v]) {
        if (col[i] == -1) col[i] = 0;
        col[v] = col[i] ^ 1;
        ans[cur.first] = D[i];
      } else if (D[i] > D[v]) {
        if (col[v] == -1) col[v] = 0;
        ans[cur.first] = D[i] - D[v];
        col[i] = col[v];
      }
    }
  }
  for (int i = (0); i < (M); ++i)
    if (ans[i] == -1) ans[i] = MAX;
  for (int i = (0); i < (N); ++i) putchar(col[i] ? 'B' : 'W');
  puts("");
  for (int i = (0); i < (M); ++i) cout << ans[i] << endl;
  return 0;
}
