#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[100005];
int val[200005];
int color[200005];
int d[100005];
void dfs(int first, int op = 0) {
  if (color[first] != -1) return;
  for (auto it : v[first]) {
    if (d[it.first] < d[first]) {
      dfs(it.first);
      color[first] = color[it.first];
      val[it.second] = d[first] - d[it.first];
      return;
    }
    if (d[it.first] == d[first] && op == 0) {
      dfs(it.first, 1);
      if (color[it.first] == -1) color[it.first] = 0, color[first] = 1;
      val[it.second] = d[it.first];
      return;
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 0; i < m; i++) {
    int first, second;
    scanf("%d %d", &first, &second);
    v[first].push_back(make_pair(second, i));
    v[second].push_back(make_pair(first, i));
  }
  for (int i = 1; i <= n; i++) {
    int Min = 1e9;
    for (auto it : v[i]) {
      Min = min(Min, d[it.first]);
    }
    printf("%d\n", i);
    if (Min > d[i]) {
      printf("-1\n");
      return 0;
    }
  }
  fill(val, val + m, 1e9);
  memset(color, -1, sizeof(color));
  for (int i = 1; i <= n; i++) {
    dfs(i);
  }
  for (int i = 1; i <= n; i++) {
    printf("%c", "BW"[color[i]]);
  }
  printf("\n");
  for (int i = 0; i < m; i++) printf("%d\n", val[i]);
}
