#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);
  for (int i = 0; i < n; i++) {
    bool ok = false;
    for (int j : g[i]) ok |= a[j] <= a[i];
    if (!ok) {
      cout << -1;
      return 0;
    }
  }
  for (auto x : edges) {
    int u = x.first;
    int v = x.second;
    if (a[u] == a[v]) {
      if (color[u] == -1 && color[v] == -1) {
        color[u] = 0;
        color[v] = 1;
      } else {
        if (color[u] == -1) color[u] = color[v] ^ 1;
        if (color[v] == -1) color[v] = color[u] ^ 1;
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (color[i] == -1) color[i] = 0;
  for (int i = 0; i < n; i++) {
    cout << (color[i] ? 'B' : 'W') << " ";
  }
  cout << endl;
  const int MAX = 1000000000;
  for (int i = 0; i < m; i++) {
    int u = edges[i].first;
    int v = edges[i].second;
    if (color[u] != color[v]) {
      cout << max(a[u], a[v]) << endl;
    } else {
      if (a[u] == a[v])
        cout << MAX << endl;
      else
        cout << abs(a[u] - a[v]) << endl;
    }
  }
  return 0;
}
