#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);
  for (int i = 0; i < n; i++) {
    cin >> v_values[i];
  }
  vector<vector<Edge>> graph(n);
  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));
  }
  vector<pair<int, int>> vi_pairs;
  for (int i = 0; i < n; i++) {
    vi_pairs.push_back(make_pair(v_values[i], i));
  }
  sort(vi_pairs.begin(), vi_pairs.end());
  vector<int> colors(n, -1);
  vector<int> edge_weights(m);
  for (const auto& vi_pair : vi_pairs) {
    int v_value, v_index;
    tie(v_value, v_index) = vi_pair;
    bool valid = false;
    for (const auto& e : graph[v_index]) {
      if (v_values[e.to] <= v_value) {
        valid = true;
      }
    }
    if (!valid) return EMPTY_PAIR;
    vector<int> used(2);
    for (const auto& e : graph[v_index]) {
      if (v_values[e.to] <= v_value) {
        if (colors[e.to] >= 0) {
          used[colors[e.to]] = 1;
        }
      }
    }
    if (used[0] == used[1]) {
      colors[v_index] = 0;
    } else if (used[0]) {
      colors[v_index] = 1;
    } else if (used[1]) {
      colors[v_index] = 0;
    } else {
      cerr << "This path should not happen!" << endl;
      exit(1);
    }
    for (const auto& e : graph[v_index]) {
      if (v_values[e.to] <= v_value) {
        if (edge_weights[e.id] == 0) {
          edge_weights[e.id] = v_value;
        }
      }
    }
  }
  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;
    }
  }
}
