#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>());
template <class T>
inline bool UpdateMin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool UpdateMax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
pair<vector<int>, vector<int>> Solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v_values(n);
  for (int i = 0; i < n; i++) {
    cin >> v_values[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<pair<int, int>> vi_pairs;
  for (int i = 0; i < n; i++) {
    vi_pairs.emplace_back(v_values[i], i);
  }
  sort(vi_pairs.begin(), vi_pairs.end());
  vector<int> colors(n, -1);
  for (const auto& vi_pair : vi_pairs) {
    int v = vi_pair.second;
    bool valid = false;
    for (const auto& edge : graph[v]) {
      if (edge_weights[edge.id] == v_values[v]) {
        valid = true;
      }
    }
    if (!valid) return EMPTY_PAIR;
    pair<int, int> min_vi = make_pair(INT_MAX, INT_MAX);
    for (const auto& edge : graph[v]) {
      if (edge_weights[edge.id] == v_values[v]) {
        UpdateMin(min_vi, make_pair(v_values[edge.to], edge.to));
      }
    }
    if (vi_pair < min_vi) {
      colors[v] = 0;
    } else {
      colors[v] = 1 - colors[min_vi.second];
    }
  }
  for (int v = 0; v < n; v++) {
    int min = INT_MAX;
    for (const auto& edge : graph[v]) {
      if (colors[edge.to] != colors[v]) {
        UpdateMin(min, edge_weights[edge.id]);
      }
    }
    if (min != v_values[v]) {
      cerr << "WA!" << endl;
      exit(1);
    }
  }
  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;
    }
  }
}
