#include <bits/stdc++.h>
using ull = unsigned long long;
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  } else
    return 0;
}
bool dbg = false;
long long N, M, D[101010];
vector<vector<pair<long long, long long>>> G;
void solve() {
  map<long long, vector<long long>> ma;
  for (long long i = 0; i < (N); ++i) {
    ma[D[i]].emplace_back(i);
  }
  vector<long long> clr(N, -1), res(M, INF);
  for (auto& it : ma) {
    long long val = it.first;
    auto vec = it.second;
    for (auto v : vec) {
      if (clr[v] != -1) continue;
      bool flag = false;
      for (auto e : G[v]) {
        long long nxt = e.first;
        if (D[nxt] > D[v]) continue;
        flag = true;
        res[e.second] = val;
        if (clr[nxt] == -1) {
          clr[v] = 0;
          clr[nxt] = 1;
        } else {
          clr[v] = !clr[nxt];
        }
        break;
      }
      if (!flag) {
        cout << -1 << endl;
        return;
      }
    }
  }
  for (long long i = 0; i < (N); ++i) {
    if (clr[i] == 0)
      cout << 'W';
    else
      cout << 'B';
  }
  cout << endl;
  for (long long i = 0; i < (M); ++i) {
    cout << res[i] << endl;
  }
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (long long i = 0; i < (N); ++i) {
    cin >> D[i];
  }
  G.resize(N);
  for (long long i = 0; i < (M); ++i) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v, i);
    G[v].emplace_back(u, i);
  }
  solve();
  return 0;
}
