#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
constexpr long double EPS = 1e-12;
long long int N, M, K, H, W, L, R;
class UnionFind {
  vector<int> parent;
  vector<int> rank;

 public:
  UnionFind(int num) {
    num++;
    parent.resize(num);
    rank.resize(num);
    for (int i = 0; i < num; i++) {
      parent[i] = i;
      rank[i] = 0;
    }
  }
  int Find(int node) {
    if (parent[node] == node)
      return node;
    else
      return parent[node] = Find(parent[node]);
  }
  void Unite(int u, int v) {
    u = Find(u);
    v = Find(v);
    if (u == v) return;
    if (rank[u] < rank[v])
      parent[u] = v;
    else {
      parent[v] = u;
      if (rank[u] == rank[v]) rank[u]++;
    }
  }
  bool Check_Same(int u, int v) { return Find(u) == Find(v); }
};
void Calculate_Depth(vector<vector<int>> &edge, vector<int> &depth,
                     int stnode) {
  depth[stnode] = 0;
  queue<int> Q;
  Q.push(stnode);
  while (!Q.empty()) {
    int cn = Q.front();
    Q.pop();
    for (auto i : edge[cn]) {
      if (depth[i] > depth[cn] + 1) {
        depth[i] = depth[cn] + 1;
        Q.push(i);
      }
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  vector<int> v(N);
  for (auto &i : v) cin >> i;
  vector<vector<int>> edge(N);
  vector<pair<int, int>> e;
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    L--, R--;
    edge[L].push_back(R);
    e.emplace_back(L, R);
  }
  string s(N, 'B');
  vector<int> dis(N, MOD);
  vector<vector<int>> t_edge(N);
  set<pair<int, pair<int, int>>> st;
  for (int i = 0; i < N; i++) {
    for (auto j : edge[i]) {
      st.insert({min(v[i], v[j]), {i, j}});
    }
  }
  UnionFind uf(N);
  for (auto i : st) {
    if (uf.Check_Same(i.second.first, i.second.second)) continue;
    uf.Unite(i.second.first, i.second.second);
    t_edge[i.second.first].push_back(i.second.second);
    t_edge[i.second.second].push_back(i.second.first);
  }
  Calculate_Depth(t_edge, dis, 0);
  for (int i = 0; i < N; i++) {
    if (dis[i] & 1) s[i] = 'W';
    bool flag = true;
    for (auto j : t_edge[i]) {
      if (v[i] >= v[j]) flag = false;
    }
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << s << endl;
  for (auto i : e) {
    cout << max(v[i.first], v[i.second]) << endl;
  }
  return 0;
}
