#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 1e5, M = 2e5, INF = 1000'000'000;
vector<PII> adj[N];
PII edges[M];
int d[N];
int wt[M];

void NO() {
  cout << -1 << endl;
  exit(0);
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n, m; cin >> n >> m;
  int d_min = INF;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    d_min = min(d_min, d[i]);
  }
  for (int i = 0; i < m; i++) {
    int u, v; cin >> u >> v; u--, v--;
    adj[u].emplace_back(i, v);
    adj[v].emplace_back(i, u);
    edges[i] = make_pair(u, v);
    wt[i] = INF;
  }

  int sw = -1, sb = -1;
  for (int u = 0; u < n; u++) {
    if (d[u] == d_min) {
      for (auto& e: adj[u]) {
        const int v = e.second, i = e.first;
        if (d[v] == d_min) {
          sw = u;
          sb = v;
          wt[i] = d_min;
          break;
        }
      }
    }
    if (sw != -1) break;
  }

  if (sw == -1) NO();

  for (int u = 0; u < n; u++) {
    bool ok = false;
    for (auto& e: adj[u]) {
      int v = e.second;
      if (d[v] <= d[u]) ok = true;
    }
    if (!ok) NO();
  }

  string col(n, '*');
  col[sw] = 'W';
  col[sb] = 'B';

  queue<int> Q;
  Q.push(sw);
  Q.push(sb);

  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (auto& e: adj[u]) {
      const int v = e.second, i = e.first;
      if (col[v] != '*' || d[v] < d[u]) continue;
      col[v] = col[u] ^ 'W' ^ 'B';
      wt[i] = d[v];
      Q.push(v);
    }
  }

  for (char ch: col) {
    assert(ch != '*');
  }

  // answer
  cout << col << '\n';
  for (int i = 0; i < m; i++) {
    cout << wt[i] << '\n';
  }

  return 0;
}
