#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> gr[maxn], tr[maxn];
int N, M, col[maxn];
int U[maxn], V[maxn];
int w[maxn], d[maxn];
bool in[maxn];
int p[maxn];
void dfs(int u) {
  for (int v : tr[u])
    if (col[v] == -1) {
      col[v] = col[u] ^ 1;
      dfs(v);
    }
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) cin >> d[i];
  for (int i = 1; i <= M; ++i) {
    cin >> U[i] >> V[i];
    gr[U[i]].emplace_back(i);
    gr[V[i]].emplace_back(i);
  }
  fill(w + 1, w + 1 + M, 1e9 + 5);
  for (int i = 1; i <= N; ++i) {
    p[i] = -1;
    for (int id : gr[i]) {
      int v = U[id] + V[id] - i;
      if (p[i] == -1 || d[p[i]] > d[v]) {
        p[i] = v;
      }
    }
    if (d[i] < d[p[i]]) {
      cout << -1;
      return 0;
    }
    tr[i].emplace_back(p[i]);
    tr[p[i]].emplace_back(i);
    for (int id : gr[i]) {
      int v = U[id] + V[id] - i;
      if (v == p[i]) {
        w[id] = d[i];
        break;
      }
    }
  }
  fill(col + 1, col + 1 + N, -1);
  for (int i = 1; i <= N; ++i) {
    if (col[i] == -1) {
      col[i] = 0;
      dfs(i);
    }
  }
  for (int i = 1; i <= N; ++i) {
    cout << (col[i] ? 'B' : 'W');
  }
  cout << '\n';
  for (int i = 1; i <= M; ++i) cout << w[i] << '\n';
}
