#include <bits/stdc++.h>
struct Edge {
  int end_a, end_b;
  int other(int vertex) const { return end_a == vertex ? end_b : end_a; }
};
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> costs(n);
  for (auto& d : costs) std::cin >> d;
  std::vector<Edge> edges(m);
  for (auto& e : edges) std::cin >> e.end_a >> e.end_b;
  std::vector<std::vector<int>> nodes(n);
  for (auto i = 0; i < m; ++i) {
    edges[i].end_a--;
    edges[i].end_b--;
    nodes[edges[i].end_a].push_back(i);
    nodes[edges[i].end_b].push_back(i);
  }
  std::string color(n, 'U');
  std::vector<int> vertexes(n);
  std::iota(vertexes.begin(), vertexes.end(), 0);
  std::sort(vertexes.begin(), vertexes.end(),
            [&costs](int i, int j) { return costs[i] < costs[j]; });
  std::vector<int> rank(n);
  for (auto i = 0; i < n; ++i) {
    rank[vertexes[i]] = i;
  }
  for (const auto v : vertexes) {
    char c = 'B';
    int max_rank = -1;
    for (const auto e : nodes[v]) {
      if (rank[edges[e].other(v)] < rank[v] &&
          max_rank < rank[edges[e].other(v)]) {
        c = color[edges[e].other(v)];
        max_rank = rank[edges[e].other(v)];
      }
    }
    switch (c) {
      case 'B':
        color[v] = 'W';
        break;
      default:
        color[v] = 'B';
    }
  }
  bool fail = false;
  for (auto i = 0; i < n; ++i) {
    fail = true;
    for (const auto e : nodes[i])
      if (costs[edges[e].other(i)] <= costs[i]) {
        fail = false;
      }
    if (fail) break;
  }
  if (fail) {
    std::cout << "-1\n";
  } else {
    std::cout << color << '\n';
    for (const auto edge : edges) {
      std::cout << std::max(costs[edge.end_a], costs[edge.end_b]) << '\n';
    }
  }
}
