#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
struct Edge {
  const int from, to, id;
  Edge(int from, int to, int id) : from(from), to(to), id(id) {}
};
const pair<vector<int>, vector<int>> EMPTY_PAIR =
    make_pair(vector<int>(), vector<int>());
pair<vector<int>, vector<int>> Solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v_values(n);
  map<int, vector<int>> value_to_vs;
  for (int i = 0; i < n; i++) {
    cin >> v_values[i];
    value_to_vs[v_values[i]].push_back(i);
  }
  vector<vector<Edge>> graph(n);
  vector<Edge> edges;
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    v1--;
    v2--;
    graph[v1].push_back(Edge(v1, v2, i));
    graph[v2].push_back(Edge(v2, v1, i));
    edges.push_back(Edge(v1, v2, i));
  }
  vector<int> edge_weights(m);
  for (int i = 0; i < m; i++) {
    edge_weights[i] = max(v_values[edges[i].from], v_values[edges[i].to]);
  }
  vector<int> colors(n, -1);
  for (int v = 0; v < n; v++) {
    bool valid = false;
    vector<int> used(2);
    for (const auto& edge : graph[v]) {
      if (edge_weights[edge.id] == v_values[v]) {
        valid = true;
      }
    }
    if (!valid) return EMPTY_PAIR;
  }
  for (const auto& value_vs : value_to_vs) {
    int value;
    vector<int> vs;
    tie(value, vs) = value_vs;
    function<void(int)> dfs_fn = [&](int v) {
      for (const auto& edge : graph[v]) {
        if (edge_weights[edge.id] == value && colors[edge.to] < 0) {
          colors[edge.to] = 1 - colors[v];
          dfs_fn(edge.to);
        }
      }
    };
    for (int v : vs) {
      for (const auto& edge : graph[v]) {
        if (edge_weights[edge.id] == value && colors[edge.to] >= 0) {
          colors[v] = 1 - colors[edge.to];
          dfs_fn(v);
        }
      }
    }
    for (int v : vs) {
      if (colors[v] < 0) {
        colors[v] = 0;
        dfs_fn(v);
      }
    }
  }
  return make_pair(colors, edge_weights);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> colors, edge_weights;
  tie(colors, edge_weights) = Solve();
  if (colors.empty()) {
    cout << -1 << endl;
  } else {
    for (int color : colors) {
      cout << "WB"[color];
    }
    cout << endl;
    for (int edge_weight : edge_weights) {
      cout << edge_weight << endl;
    }
  }
}
