#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (int)1e9;
const int N = 1e5;
const int M = 2 * (int)1e5;
vector<pair<int, int>> conns[N];
int dist[M];
int dep[N];
int dfs(int i, string& col) {
  int res = 1;
  for (auto pr : conns[i]) {
    int t = pr.first;
    if (dep[t] == dep[i] && col[t] == '_') {
      dist[pr.second] = dep[i];
      col[t] = (col[i] == 'W' ? 'B' : 'W');
      res += dfs(t, col);
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> ds(n);
  for (int i = 0; i < n; ++i) {
    cin >> dep[i];
    ds[i] = {dep[i], i};
  }
  sort(ds.begin(), ds.end());
  int d0 = ds[0].first;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    conns[a].push_back({b, i});
    conns[b].push_back({a, i});
    dist[i] = INF;
  }
  bool fail = false;
  string col(n, '_');
  for (int i = 0; i < n; ++i) {
    if (dep[i] > d0 || col[i] != '_') continue;
    col[i] = 'W';
    int sub = dfs(i, col);
    if (sub == 1) fail = true;
  }
  for (auto pr : ds) {
    int i = pr.second;
    if (col[i] != '_') continue;
    for (auto pr : conns[i]) {
      int t = pr.first;
      if (col[t] != '_' && dep[t] <= dep[i]) {
        dist[pr.second] = dep[i];
        col[i] = (col[t] == 'W' ? 'B' : 'W');
        break;
      }
    }
  }
  if (fail) {
    cout << -1 << '\n';
  } else {
    cout << col << '\n';
    for (int i = 0; i < m; ++i) cout << dist[i] << ' ';
    cout << '\n';
  }
}
