#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> adj[100000];
vector<tuple<int, int, int>> E;
bool used[100000];
string ans;
int V[100000], P[100000], res[200000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ((void)0);
  ((void)0);
  ((void)0);
  int N, M, m = 0x7fffffff, mcnt = 0, tot = 1;
  priority_queue<pair<int, int>> Q;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> V[i];
    if (V[i] < m) {
      m = V[i];
      mcnt = 1;
    } else if (V[i] == m)
      mcnt++;
    P[i] = -1;
  }
  if (mcnt == 1) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    adj[--a].emplace_back(--b, i);
    adj[b].emplace_back(a, i);
    res[i] = 1e9;
  }
  ans.resize(N);
  for (int i = 0; i < N; i++)
    if (m == V[i]) {
      Q.emplace(-V[i], i);
      used[i] = true;
      ans[i] = 'B';
      break;
    }
  while (!Q.empty()) {
    int c = Q.top().second;
    Q.pop();
    tot++;
    for (auto n : adj[c])
      if (V[n.first] >= V[c] && !used[n.first]) {
        used[n.first] = true;
        res[n.second] = V[n.first];
        ans[n.first] = ans[c] == 'B' ? 'W' : 'B';
        Q.emplace(-V[n.first], n.first);
      }
  }
  if (tot < N) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << '\n';
  for (int i = 0; i < M; i++) cout << res[i] << '\n';
  return 0;
}
