#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct node {
  int u, val;
  node() {}
  node(int _u, int _v) {
    u = _u;
    val = _v;
  }
  bool operator<(const node &b) const { return val < b.val; }
};
priority_queue<node> q;
int a[N], n, m, col[N], val[N], vis[N];
vector<pair<int, int> > e[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int fl = 1, u, v;
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v;
    e[u].push_back(make_pair(v, i));
    e[v].push_back(make_pair(u, i));
    if (a[u] == a[v])
      q.push(node(u, a[u])), q.push(node(v, a[v])),
          col[u] = 1, col[v] = 0, vis[u] = 1, vis[v] = 1, val[i] = a[u];
  }
  while (!q.empty()) {
    int u = q.top().u;
    q.pop();
    for (int i = 0; i < e[u].size(); ++i)
      if (!vis[e[u][i].first] && a[e[u][i].first] >= val[u])
        vis[e[u][i].first] = 1, q.push(node(e[u][i].first, a[e[u][i].first])),
        col[e[u][i].first] = col[u] ^ 1, val[e[u][i].second] = a[e[u][i].first];
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) return puts("-1"), 0;
  for (int i = 1; i <= n; ++i) cout << (col[i] == 0 ? "B" : "W");
  cout << endl;
  for (int i = 1; i <= m; ++i)
    cout << (val[i] == 0 ? (int)1e9 : val[i]) << endl;
  return 0;
}
