#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;
  }
  std::vector<bool> added(n, false);
  std::vector<int> edge_cost(m);
  std::vector<int> stack;
  stack.reserve(n);
  bool fail = false;
  for (auto i = 0; i < n; ++i) {
    added[vertexes[i]] = true;
    stack.push_back(vertexes[i]);
    if (i + 1 == n || costs[vertexes[i + 1]] != costs[vertexes[i]]) {
      std::sort(stack.begin(), stack.end());
      for (const auto v : stack) {
        char other_color = 'N';
        int max_other = -1;
        bool has_edge = false;
        for (const auto e : nodes[v])
          if (added[edges[e].other(v)]) {
            edge_cost[e] = costs[v];
            has_edge = true;
            if (rank[edges[e].other(v)] < rank[v] &&
                max_other < rank[edges[e].other(v)]) {
              other_color = color[edges[e].other(v)];
              max_other = rank[edges[e].other(v)];
            }
          }
        if (!has_edge) {
          fail = true;
          break;
        }
        switch (other_color) {
          case 'B':
            color[v] = 'W';
            break;
          case 'W':
            color[v] = 'B';
            break;
          case 'N':
            color[v] = 'B';
            break;
          default:
            throw 0;
        }
      }
      stack.clear();
    }
    if (fail) break;
  }
  if (fail) {
    std::cout << "-1\n";
  } else {
    std::cout << color << '\n';
    for (const auto c : edge_cost) std::cout << c << '\n';
  }
}
