#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vector<pair<int, int>> edges;
  vector<vector<int>> g(n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
    edges.emplace_back(u, v);
  }
  vector<int> color(n, -1);
  vector<vector<int>> to(n);
  int s = *min_element(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[i] != s) continue;
    for (int j : g[i]) {
      if (a[j] != s) continue;
      to[i].push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == s && to[i].empty()) {
      cout << -1;
      return 0;
    }
  }
  function<void(int, int)> dfs = [&](int v, int c) {
    color[v] = c;
    for (int i : to[v]) {
      if (~color[i]) continue;
      dfs(i, c ^ 1);
    }
  };
  for (int i = 0; i < n; i++) {
    if (a[i] == s && color[i] == -1) dfs(i, 0);
    if (a[i] > s) color[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cout << (color[i] ? 'B' : 'W') << " ";
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    int u = edges[i].first;
    int v = edges[i].second;
    if (a[u] > a[v]) swap(u, v);
    if (a[u] != a[v]) {
      if (a[u] == s) {
        cout << (color[u] == color[v] ? a[v] - a[u] : a[v]) << endl;
      } else
        cout << abs(a[u] - a[v]) << endl;
    } else {
      if (a[u] > s)
        cout << 0 << endl;
      else {
        cout << s << endl;
      }
    }
  }
  return 0;
}
