#include <bits/stdc++.h>
using namespace std;
long long N, M, H, W, K, Q, A, B;
string S, T;
const long long MOD = (1e+9) + 7;
const long long INF = 1LL << 60;
struct edge {
  int to, id;
  edge(){};
  edge(int a, int b) {
    to = a;
    id = b;
  }
};
int main() {
  cin >> N >> M;
  vector<vector<edge> > G(N, vector<edge>(0));
  vector<long long> d(N), color(N, 0), ord(N), ecost(M, -1);
  for (int i = 0; i < N; i++) {
    cin >> d[i];
    ord[i] = i;
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    --A;
    --B;
    G[A].emplace_back(B, i);
    G[B].emplace_back(A, i);
  }
  sort(ord.begin(), ord.end(), [&](int x, int y) { return d[x] < d[y]; });
  for (int i = 0; i < N; i++) {
    int v = ord[i];
    bool update = false;
    for (edge e : G[v]) {
      if (color[e.to] != 0) {
        color[v] = -color[e.to];
        ecost[e.id] = d[v];
        update = true;
        break;
      }
    }
    if (!update) {
      color[v] = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    bool ok = false;
    for (edge e : G[i]) {
      if (color[i] == -color[e.to] && d[i] == ecost[e.id]) {
        ok = true;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) cout << (color[i] == 1 ? 'B' : 'W');
  cout << endl;
  for (int i = 0; i < M; i++)
    cout << (ecost[i] == -1 ? long long(1e+9) : ecost[i]) << endl;
}
