#include <bits/stdc++.h>
using namespace std;
int n, m;
string S;
const int INF = 1e9;
vector<int> D;
vector<vector<array<int, 3>>> E;
vector<int> C;
vector<bool> visited, changed, cleared;
int main() {
  cin >> n >> m;
  D.resize(n);
  copy_n(istream_iterator<int>(cin), n, D.begin());
  E.resize(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back({D[v], v, i});
    E[v].push_back({D[u], u, i});
  }
  for (int i = 0; i < n; i++) sort(E[i].begin(), E[i].end());
  for (int i = 0; i < n; i++) S.push_back('a');
  C.assign(m, INF);
  visited.resize(n);
  for (int i = 0; i < n; i++) {
    auto num = E[i][0][2];
    if (C[num] == D[i]) continue;
    if (C[num] < D[i] or visited[i]) {
      puts("-1");
      return 0;
    }
    visited[i] = true;
    auto to = E[i][0][1];
    S[i] = 'B';
    S[to] = 'W';
    C[num] = D[i];
  }
  cout << S << endl;
  for (const auto &c : C) cout << c << endl;
}
