#include <bits/stdc++.h>
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];
  }
  return os;
}
const int N = 100010, M = 200010;
int n, m, dmin;
int d[N];
vector<pair<int, int>> g[N];
char s[N];
int ans[M];
void gg() {
  cout << "-1\n";
  exit(0);
}
void dfs(int u) {
  bool f = false;
  for (const auto& pr : g[u]) {
    int v, id;
    tie(v, id) = pr;
    if (d[v] == dmin) f = true;
    if (s[v] || d[v] < d[u]) continue;
    s[v] = s[u] == 'B' ? 'W' : 'B';
    ans[id] = d[v];
    dfs(v);
  }
  if (d[u] == dmin && !f) gg();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> d[i];
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  fill(ans + 1, ans + m + 1, (int)1e9);
  dmin = *min_element(d + 1, d + n + 1);
  for (int i = 1; i <= n; ++i)
    if (d[i] == dmin && !s[i]) {
      s[i] = 'B';
      dfs(i);
    }
  for (int i = 1; i <= n; ++i)
    if (!s[i]) gg();
  cout << (s + 1) << '\n';
  for (int i = 1; i <= m; ++i) cout << ans[i] << '\n';
  return 0;
}
