#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > G[N];
int d[N], id[N], col[N], val[N << 1];
bool cmp(int x, int y) { return d[x] < d[y]; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    id[i] = i, col[i] = -1;
  }
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back({v, i});
    G[v].push_back({u, i});
  }
  sort(id + 1, id + n + 1);
  for (int i = 1; i <= n; i++) {
    int u = id[i];
    if (~col[u]) continue;
    bool f = false;
    for (auto it : G[u]) {
      int v = it.first;
      if (d[u] >= d[v]) {
        if (~col[v])
          col[u] = col[v] ^ 1;
        else
          col[v] = 0, col[u] = col[v] ^ 1;
        val[it.second] = d[u];
        f = true;
        break;
      }
    }
    if (!f) {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%c", col[i] ? 'W' : 'B');
  }
  printf("\n");
  for (int i = 1; i <= m; i++) {
    if (!val[i]) val[i] = 1e9;
    printf("%d\n", val[i]);
  }
  return 0;
}
