#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<pair<long long, long long> > A(N);
  vector<long long> D(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i].first;
    D[i] = A[i].first;
    A[i].second = i;
  }
  vector<vector<pair<long long, long long> > > g(N);
  long long INF = 1000000000;
  vector<long long> res(M, INF);
  for (long long i = 0; i < M; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
  }
  sort(A.begin(), A.end());
  string col(N, '.');
  for (long long i = 0; i < N; i++) {
    long long val = A[i].first;
    long long idx = A[i].second;
    bool ok = false;
    for (const pair<long long, long long> &p : g[idx]) {
      if (col[p.first] != '.') {
        col[idx] = (col[p.first] == 'B' ? 'W' : 'B');
        res[p.second] = val;
        ok = true;
        break;
      }
    }
    if (!ok) {
      for (const pair<long long, long long> &p : g[idx]) {
        if (D[p.first] == val) {
          col[idx] = 'B';
          res[p.second] = val;
          ok = true;
          break;
        }
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << col << endl;
  for (long long i = 0; i < M; i++) {
    cout << res[i] << endl;
  }
}
