#include <bits/stdc++.h>
using namespace std;
int N, M, INF = 1e9;
int used[100000], C[200000], S[100000];
vector<pair<int, int> > G[100000];
vector<pair<int, int> > D;
int main() {
  cin >> N >> M;
  for (int i = 0; i < int(N); i++) {
    int d;
    cin >> d;
    D.push_back(pair<int, int>(d, i));
    S[i] = -1;
  }
  for (int i = 0; i < int(M); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(pair<int, int>(v, i));
    G[v].push_back(pair<int, int>(u, i));
  }
  sort((D).begin(), (D).end());
  for (int i = 0; i < int(N); i++) {
    int now = D[i].second, f = 0;
    if (used[now]) continue;
    for (int j = 0; j < int(G[now].size()); j++) {
      int to = G[now][j].first;
      if (D[to].first <= D[now].first) {
        C[G[now][j].second] = D[i].first;
        if (S[to] == -1) S[to] = 1;
        f = 1;
        S[now] = 1 - S[to];
        used[now] = 1;
        used[to] = 1;
        break;
      }
    }
    if (!f) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < int(N); i++) {
    if (S[i])
      cout << 'W';
    else
      cout << 'B';
  }
  cout << "\n";
  for (int i = 0; i < int(M); i++) {
    if (!C[i])
      cout << INF << endl;
    else
      cout << C[i] << endl;
  }
  return 0;
}
