#include <bits/stdc++.h>
using namespace std;
int N, M;
int D[1 << 17];
map<pair<int, int>, int> E;
vector<pair<int, int> > edges;
vector<int> G[1 << 17];
int color[1 << 17];
int main() {
  cin >> N >> M;
  vector<pair<int, int> > d(N);
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    d[i] = make_pair(D[i], i);
  }
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    edges.push_back(minmax(u, v));
    G[u].push_back(v);
    G[v].push_back(u);
  }
  sort(d.begin(), d.end());
  if (d[0].first != d[1].first) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (i + 1 < N && d[i].first == d[i + 1].first && !color[d[i].second]) {
      color[d[i].second] = 1;
      color[d[i + 1].second] = 2;
    }
    int u = d[i].second;
    for (int v : G[u]) {
      if (D[v] <= D[u]) {
        if (!color[u] && color[v]) {
          color[u] = 3 - color[v];
        }
        E[minmax(u, v)] = D[u];
      }
    }
    if (!color[u]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) cout << (color[i] == 1 ? 'W' : 'B');
  cout << endl;
  for (pair<int, int> p : edges) cout << E[p] << endl;
}
