#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> D(N);
  for (int i = 0; i < N; i++) {
    cin >> D[i];
  }
  vector<vector<pair<int, int>>> E(N);
  for (int i = 0; i < M; i++) {
    int U, V;
    cin >> U >> V;
    U--;
    V--;
    E[U].push_back(make_pair(i, V));
    E[V].push_back(make_pair(i, U));
  }
  vector<int> C(N, -1);
  vector<int> W(M, INF);
  queue<int> Q;
  for (int v = 0; v < N; v++) {
    for (auto P : E[v]) {
      int id = P.first;
      int w = P.second;
      if (D[v] == D[w]) {
        if (C[v] == -1) {
          if (C[w] == -1) {
            C[v] = 0;
            C[w] = 1;
            W[id] = D[v];
            Q.push(v);
            Q.push(w);
          } else {
            C[v] = 1 - C[w];
            W[id] = D[v];
            Q.push(v);
          }
        } else if (C[w] == -1) {
          C[w] = 1 - C[v];
          W[id] = D[v];
          Q.push(w);
        }
      }
    }
  }
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    for (auto P : E[v]) {
      int id = P.first;
      int w = P.second;
      if (C[w] == -1 && D[w] > D[v]) {
        C[w] = 1 - C[v];
        W[id] = D[w];
        Q.push(w);
      }
    }
  }
  bool ok = true;
  for (int i = 0; i < N; i++) {
    if (C[i] == -1) {
      ok = false;
    }
  }
  if (!ok) {
    cout << "No" << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (C[i] == 0) {
        cout << 'W';
      }
      if (C[i] == 1) {
        cout << 'B';
      }
    }
    cout << endl;
    for (int i = 0; i < M; i++) {
      cout << W[i] << endl;
    }
  }
}
