#include <bits/stdc++.h>
using namespace std;
int D[100010], ans_e[200010], ans_v[100010], mx = 1e9;
pair<int, int> dd[100010];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) {
    cin >> D[i];
    dd[i - 1] = make_pair(D[i], i);
  }
  sort(dd, dd + N);
  vector<vector<pair<int, int>>> G(N + 1);
  for (int i = 0; i < M; ++i) {
    int u, v;
    cin >> u >> v;
    G[u].emplace_back(make_pair(v, i));
    G[v].emplace_back(make_pair(u, i));
  }
  for (int i = 0; i < N; ++i) {
    int s = dd[i].second;
    bool flag = true;
    for (int t = 0; t < G[s].size(); ++t) {
      if (D[G[s][t].first] <= D[s]) {
        ans_e[G[s][t].second] = D[s];
        if (ans_v[G[s][t].first] == 0) {
          ans_v[G[s][t].first] = 1;
          ans_v[s] = 2;
        } else {
          ans_v[s] = 3 - ans_v[G[s][t].first];
        }
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= N; ++i) cout << (ans_v[i] == 1 ? 'B' : 'W');
  cout << endl;
  for (int i = 0; i < M; ++i) {
    if (ans_e[i] == 0)
      cout << mx << endl;
    else
      cout << ans_e[i] << endl;
  }
  return 0;
}
