#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y;
  bool operator<(const P &a) const { return y > a.y; };
};
int a, b, c, d, i, k, n, m, e, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
                               dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
int o[100031];
int l[200055];
int j[100101];
long long x, y, z, mod = 1000000007;
char r[1];
P u[1];
queue<int> q;
set<int> s;
map<int, int> p;
vector<P> v[100101], v1;
bool as(P a, P b) { return a.y < b.y; }
void f(int n) {
  for (int h = 0; h < v[n].size(); h++)
    if (j[v[n][h].x] < 0 && o[v[n][h].x] == l[v[n][h].y]) {
      k++;
      j[v[n][h].x] = 1 - j[n];
      f(v[n][h].x);
    }
}
int main() {
  scanf("%d %d", &a, &b);
  c = mod;
  for (int t = 1; t <= a; t++) {
    scanf("%d", &o[t]);
    c = min(o[t], c);
    if (c == o[t]) e = t;
  }
  for (int t = 1; t <= b; t++) {
    scanf("%d %d", &n, &m);
    l[t] = max(o[n], o[m]);
    v[n].push_back({m, t});
    v[m].push_back({n, t});
  }
  for (int t = 1; t <= a; t++) {
    for (int h = 0; h < v[t].size(); h++)
      if (l[v[t][h].y] == o[t]) goto qwe;
    puts("-1");
    return 0;
  qwe:;
  }
  memset(j, -1, sizeof(j));
  for (int t = 1; t <= a; t++)
    if (j[t] < 0) {
      k++;
      j[t] = 1;
      f(t);
    }
  if (k < a) {
    puts("-1");
    return 0;
  }
  for (int t = 1; t <= a; t++)
    if (!j[t])
      printf("B");
    else
      printf("W");
  puts("");
  for (int t = 1; t <= b; t++)
    if (l[t])
      printf("%d\n", l[t]);
    else
      printf("1000000000\n");
}
