#include <bits/stdc++.h>
using namespace std;
int n, m;
int D[100005];
int U[100005];
int V[100005];
vector<int> edge[100005];
int col[100005];
int dfs(int x) {
  int ret = 1;
  for (int i : edge[x]) {
    if (col[i]) continue;
    if (D[i] != D[x]) continue;
    col[i] = 3 - col[x];
    ret += dfs(i);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> D[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> U[i] >> V[i];
    edge[U[i]].push_back(V[i]);
    edge[V[i]].push_back(U[i]);
  }
  int prv = 2;
  for (int x = 1; x <= n; x++) {
    if (col[x]) continue;
    bool en = false;
    for (int i : edge[x]) {
      if (D[i] < D[x]) {
        en = true;
        break;
      }
    }
    prv = 3 - prv;
    col[x] = prv;
    col[x] = 1;
    if (dfs(x) == 1 && !en) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << "BW"[col[i] - 1];
  }
  cout << '\n';
  for (int i = 1; i <= m; i++) {
    int c1 = col[U[i]], c2 = col[V[i]];
    if (c1 == c2) {
      cout << max(1, abs(D[U[i]] - D[V[i]])) << '\n';
    } else {
      cout << max(D[U[i]], D[V[i]]) << '\n';
    }
  }
}
