#include <bits/stdc++.h>
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
const int inf = INT_MAX / 2;
const long long infl = 1LL << 60;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int N, M, D[101010], U[201010], V[201010];
vector<pair<int, int>> E[201010];
int MA = 1000000000;
int col[101010], costs[201010];
int depth[101010];
void dfs(int cu, int dpt = 1) {
  depth[cu] = dpt;
  for (auto& p : E[cu]) {
    int to = p.first;
    int i = p.second;
    if (depth[i] != 0) {
      costs[i] = MA;
      continue;
    }
    if (D[cu] < D[to]) {
      costs[i] = D[to] - D[cu];
      col[to] = col[cu];
    } else {
      costs[i] = D[to];
      col[to] = 1 - col[cu];
    }
    dfs(to, dpt + 1);
  }
}
void _main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> D[i];
  int root = -1;
  for (int i = 0; i < M; i++) {
    cin >> U[i] >> V[i];
    U[i]--;
    V[i]--;
    E[U[i]].push_back({V[i], i});
    E[V[i]].push_back({U[i], i});
    if (D[U[i]] == D[V[i]]) root = U[i];
  }
  if (root < 0) {
    printf("-1\n");
    return;
  }
  dfs(root);
  for (int i = 0; i < N; i++) {
    if (col[i] == 0)
      printf("W");
    else
      printf("B");
  }
  printf("\n");
  for (int i = 0; i < M; i++) {
    if (i) printf(" ");
    printf("%d", costs[i]);
  }
  printf("\n");
}
