#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int INF = 1e9;
int n, m;
int val[N + 5];
vector<pair<int, int> > adj[N + 5];
int ans[2 * N + 5];
bool done[N + 5];
bool col[N + 5];
int main() {
  memset(ans, -1, sizeof(ans));
  scanf("%d%d", &n, &m);
  int mini = INF;
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]), mini = min(mini, val[i]);
  int b;
  for (int i = 1; i <= n; i++)
    if (val[i] == mini) b = i;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(make_pair(v, i));
    adj[v].push_back(make_pair(u, i));
  }
  priority_queue<pair<pair<int, int>, pair<int, int> > > pq;
  pq.push(make_pair(make_pair(-val[b], b), make_pair(-1, -1)));
  int cnt = 0;
  bool bdone = 0;
  while (!pq.empty()) {
    int node = pq.top().first.second;
    int nil = -pq.top().first.first;
    int dari = pq.top().second.first;
    int idx = pq.top().second.second;
    pq.pop();
    if (done[node]) continue;
    if (dari == -1) {
      done[node] = 1;
      col[node] = 1;
      cnt++;
    } else {
      if (val[node] < val[dari]) {
        continue;
      } else {
        col[node] = 1 ^ col[dari];
        ans[idx] = val[node];
        done[node] = 1;
        cnt++;
      }
    }
    for (int i = 0; i < adj[node].size(); i++) {
      int ke = adj[node][i].first;
      int idx = adj[node][i].second;
      if (done[ke]) continue;
      pq.push(make_pair(make_pair(-val[ke], ke), make_pair(node, idx)));
    }
  }
  bool dpt = 0;
  for (int i = 0; i < adj[b].size(); i++) {
    int idx = adj[b][i].second;
    if (ans[idx] == mini) dpt = 1;
  }
  if (cnt != n || !dpt) {
    printf("-1\n");
  } else {
    for (int i = 1; i <= n; i++) {
      if (col[i])
        printf("B");
      else
        printf("W");
    }
    printf("\n");
    for (int i = 1; i <= m; i++) {
      if (ans[i] == -1)
        printf("%d\n", INF);
      else
        printf("%d\n", ans[i]);
    }
  }
  return 0;
}
