#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MN = 2e5 + 5;
int N, M, D[MN], C[MN], par[MN], minD = 1e9, cnt, num;
pair<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);
  }
}
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++) {
    if (D[i] == minD) {
      ch[i] = 1;
      num++;
    }
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    E[i].first = a;
    E[i].second = b;
    if (ch[a] && ch[b]) {
      if (fnd(a) != fnd(b)) {
        join(a, b);
        T[a].push_back(b);
        T[b].push_back(a);
        tree[i] = 1;
        cnt++;
      }
    }
  }
  if (cnt < num - 1 || num == 1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    int a = E[i].first;
    int b = E[i].second;
    if (fnd(a) != fnd(b)) {
      join(a, b);
      T[a].push_back(b);
      T[b].push_back(a);
      tree[i] = 1;
      cnt++;
    }
  }
  if (cnt < N - 1) {
    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 << max(D[E[i].first], D[E[i].second]) << '\n';
    else
      cout << "1000000000\n";
  }
}
