#include <bits/stdc++.h>
using namespace std;
std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point owari;
int col[100009];
int a[100009], n, m;
vector<int> v[100009];
bool init[100009];
int A1[200009], A2[200009];
map<pair<int, int>, int> cost;
void dfs(int now, int sum, int per) {
  if (per != -1) {
    if (1 || init[per]) {
      col[now] = col[per] ^ 1;
    } else {
      col[now] = col[per];
    }
  }
  for (int i = 0; i < v[now].size(); i++) {
    int nex = v[now][i];
    if (col[nex] != -1) continue;
    if (a[nex] < a[now]) continue;
    cost[pair<int, int>(now, nex)] = a[nex];
    cost[pair<int, int>(nex, now)] = a[nex];
    dfs(nex, a[nex], now);
  }
}
signed main() {
  memset(col, -1, sizeof(col));
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    A1[i] = A;
    A2[i] = B;
    v[A].emplace_back(B);
    v[B].emplace_back(A);
    if (a[A] == a[B]) {
      if (col[A] != -1) {
        col[B] = col[A] ^ 1;
      } else if (col[B] != -1) {
        col[A] = col[B] ^ 1;
      } else {
        col[A] = 0;
        col[B] = 1;
      }
      cost[pair<int, int>(A, B)] = a[A];
      cost[pair<int, int>(B, A)] = a[A];
      init[A] = init[B] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (col[i] == -1) continue;
    if (!init[i]) continue;
    dfs(i, 0, -1);
  }
  for (int i = 0; i < n; i++) {
    if (col[i] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (col[i] == 0)
      cout << 'B';
    else
      cout << 'W';
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    if (cost.count(pair<int, int>(A1[i], A2[i]))) {
      cout << cost[pair<int, int>(A1[i], A2[i])] << endl;
    } else {
      cout << 1000000000 << endl;
    }
  }
}
