#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MN = 2e5 + 5;
int N, M, D[MN], C[MN], Q[MN], par[MN], minD = 1e9, cnt, num;
pair<pair<int, int>, int> E[MN];
bool ch[MN], tree[MN], col[MN];
vector<int> T[MN];
int fnd(int a) { return par[a] == a ? a : par[a] = fnd(par[a]); }
void join(int a, int b) {
  a = fnd(a), b = fnd(b);
  par[b] = a;
}
void dfs(int s, int r) {
  for (int e : T[s]) {
    if (e == r) continue;
    col[e] = !col[s];
    dfs(e, s);
  }
}
bool cmp(pair<pair<int, int>, int> p, pair<pair<int, int>, int> q) {
  return max(D[p.first.first], D[p.first.second]) <
         max(D[q.first.first], D[q.first.second]);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    par[i] = i;
    cin >> D[i];
    minD = min(minD, D[i]);
  }
  for (int i = 1; i <= N; i++) {
    Q[i] = 1e9 + 7;
    if (D[i] == minD) {
      ch[i] = 1;
      num++;
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> E[i].first.first >> E[i].first.second;
    E[i].second = i;
  }
  sort(E, E + N, cmp);
  for (int i = 0; i < M; i++) {
    int a = E[i].first.first;
    int b = E[i].first.second;
    if (fnd(a) != fnd(b)) {
      join(a, b);
      T[a].push_back(b);
      T[b].push_back(a);
      C[E[i].second] = max(D[a], D[b]);
      Q[a] = min(Q[a], C[E[i].second]);
      Q[b] = min(Q[b], C[E[i].second]);
      tree[E[i].second] = 1;
      cnt++;
    }
  }
  if (cnt < N - 1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (Q[i] != D[i]) {
      cout << -1;
      return 0;
    }
  }
  dfs(1, 1);
  for (int i = 1; i <= N; i++) {
    if (col[i])
      cout << 'B';
    else
      cout << 'W';
  }
  cout << '\n';
  for (int i = 0; i < M; i++) {
    if (tree[i])
      cout << C[i] << '\n';
    else
      cout << "1000000000\n";
  }
}
