#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<ll> D(N);
  for (int i = 0; i < N; i++) scanf("%lld", &D[i]);
  vector<vector<int> > G(N);
  map<pair<int, int>, ll> edge_map;
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    edge_map[make_pair(u, v)] = i;
    edge_map[make_pair(v, u)] = i;
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }
  ll mi = *min_element(D.begin(), D.end());
  if (count(D.begin(), D.end(), mi) < 2) {
    cout << -1 << endl;
    return 0;
  }
  vector<bool> used(N);
  vector<ll> color(N, -1), ans(M, -1);
  priority_queue<int, vector<int>, function<bool(int, int)> > que(
      [&](int u, int v) { return D[u] > D[v]; });
  bool cond = true;
  for (int i = 0; i < N; i++) {
    if (D[i] != mi) continue;
    int cur = i, cnt = 0;
    if (color[cur] < 0) color[cur] = 0;
    for (auto to : G[cur]) {
      if (D[to] == mi) {
        cnt++;
        if (cur > to) continue;
        if (color[to] < 0) {
          color[to] = color[cur] ^ 1;
        }
        que.emplace(cur);
        que.emplace(to);
        used[cur] = used[to] = true;
        ans[edge_map[make_pair(cur, to)]] = D[i];
      }
    }
    cond &= (cnt > 0);
  }
  if (!cond) {
    cout << -1 << endl;
    return 0;
  }
  while (que.size()) {
    int cur = que.top();
    que.pop();
    for (auto to : G[cur]) {
      if (color[to] >= 0) {
        ans[edge_map[make_pair(cur, to)]] = max(D[cur], D[to]);
      } else {
        ans[edge_map[make_pair(cur, to)]] = max(D[cur], D[to]);
        color[to] = color[cur] ^ 1;
        if (!used[to]) {
          used[to] = true;
          que.emplace(to);
        }
      }
    }
  }
  bool ok = true;
  for (int i = 0; i < N; i++) {
    ll min_val = LONGINF, cur = i;
    for (auto to : G[cur]) {
      if (color[cur] == color[to]) continue;
      chmin<ll>(min_val, ans[edge_map[make_pair(cur, to)]]);
    }
    ok &= (D[i] == min_val);
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  string color_str(N, '?');
  for (int i = 0; i < N; i++) {
    if (color[i] == 0)
      color_str[i] = 'B';
    else if (color[i] == 1)
      color_str[i] = 'W';
    else
      assert(false);
  }
  for (int i = 0; i < M; i++) {
    assert(ans[i] > 0);
  }
  cout << color_str << endl;
  for (int i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
