#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > g[200010];
bool vis[200010], col[200010];
long long n, m, a[200010], b[200010], d[200010], len[200010];
void dfs(long long x, bool c, long long eid, long long bef) {
  if (vis[x]) return;
  if (d[x] < bef) return;
  vis[x] = 1;
  col[x] = c;
  len[eid] = d[x];
  for (auto y : g[x]) {
    dfs(y.first, c ^ 1, y.second, d[x]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  long long mi = 1e17;
  for (int i = 0; i < n; i++) mi = min(mi, d[i]);
  int eid = -1;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    g[a[i]].push_back(make_pair(b[i], i));
    g[b[i]].push_back(make_pair(a[i], i));
    if (d[a[i]] == mi && d[b[i]] == mi) {
      eid = i;
    }
    len[i] = 1e9;
  }
  if (!~eid) {
    cout << -1 << endl;
    return 0;
  }
  vis[a[eid]] = 1;
  dfs(b[eid], 0, eid, mi);
  vis[a[eid]] = 0;
  dfs(a[eid], 1, eid, mi);
  bool ok = 1;
  for (int i = 0; i < n; i++) ok &= vis[i];
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) cout << (col[i] ? "B" : "W");
  cout << endl;
  for (int i = 0; i < m; i++) cout << len[i] << endl;
}
