#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int mn[N];
inline bool cmp(pair<int, int>& i1, pair<int, int>& i2) {
  return (mn[i1.first] > mn[i2.first]);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > vec;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec.push_back({x, i});
  }
  sort(vec.begin(), vec.end());
  memset(mn, 63, sizeof(mn));
  vector<pair<int, int> > g[n];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  int ans[m];
  bool mark[n];
  memset(mark, 0, sizeof(mark));
  int col[n];
  memset(col, 0, sizeof(col));
  for (pair<int, int> x : vec) {
    int v = x.second;
    sort(g[v].begin(), g[v].end(), cmp);
    for (pair<int, int> y : g[v]) {
      int u = y.first;
      if (mark[u] && mn[v] > mod) {
        mn[u] = min(mn[u], x.first);
        mn[v] = min(mn[v], x.first);
        ans[y.second] = x.first;
        col[v] = 1 - col[u];
      } else if (mark[u]) {
        ans[y.second] = x.first;
      }
    }
    mark[x.second] = true;
  }
  for (pair<int, int> x : vec)
    if (mn[x.second] != x.first) return cout << -1, 0;
  for (int i = 0; i < n; i++) cout << ((col[i] == 0) ? "B" : "W");
  cout << "\n";
  for (int i = 0; i < m; i++) cout << ans[i] << "\n";
  return 0;
}
