#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;
    --e.end_a;
    --e.end_b;
  }
  std::vector<std::vector<int>> nodes(n);
  std::vector<std::vector<int>> to(n);
  for (auto i = 0; i < m; ++i) {
    nodes[edges[i].end_a].push_back(i);
    nodes[edges[i].end_b].push_back(i);
    to[edges[i].end_a].push_back(edges[i].end_b);
    to[edges[i].end_b].push_back(edges[i].end_a);
  }
  std::vector<int> color(n, -1);
  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;
  }
  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::stack<int> stack;
    stack.push(0);
    color[0] = 0;
    while (!stack.empty()) {
      const auto top = stack.top();
      stack.pop();
      for (const auto t : to[top])
        if (color[t] == -1) {
          color[t] = 1 - color[top];
          stack.push(t);
        }
    }
    for (auto i = 0; i < n; ++i) {
      if (color[i] == 0) {
        std::cout << 'B';
      } else
        std::cout << 'W';
    }
    std::cout << std::endl;
    for (const auto edge : edges) {
      std::cout << std::max(costs[edge.end_a], costs[edge.end_b]) << '\n';
    }
  }
}
