#include <bits/stdc++.h>
using namespace std;
int d[100100];
int id[100100];
int c[100100];
int ex[200100], ey[200100], ans[200100];
char col[100100];
vector<int> g[100100];
bool cmp(int i, int j) { return d[i] < d[j]; }
int main() {
  int n, m;
  bool fail = false;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &ex[i], &ey[i]);
    g[ex[i]].push_back(i);
    g[ey[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) id[i] = i + 1;
  sort(id, id + n, cmp);
  for (int i = 0; i < n; i++) {
    int u = id[i];
    fail = true;
    for (int j = 0; j < g[u].size(); j++) {
      int t = g[u][j];
      int v = ex[t] ^ ey[t] ^ u;
      if (d[v] <= d[u]) {
        fail = false;
        ans[t] = d[u];
        if (!col[u]) {
          if (col[v] == 'B')
            col[u] = 'W';
          else if (col[v] == 'W')
            col[u] = 'B';
          else
            col[u] = 'B';
        }
      }
    }
    if (fail) break;
  }
  if (fail)
    puts("-1");
  else {
    puts(col + 1);
    for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
