#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
vector<pii> T[N];
int d[N];
int c[N];
int b[N];
vector<int> R[N];

void dfs(int u){
  for(auto x : R[u]){
    if(b[x] == -1){
      b[x]=1-b[u];
      dfs(x);
    }
  }
}

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 1; i <= n; i ++ ){
    cin >> d[i];
    b[i]=-1;
    c[i]=0;
  }
  int u, v;
  for(int i = 1; i <= m; i ++ ){
    cin >> u >> v;
    T[u].push_back(mp(v,i));
    T[v].push_back(mp(u,i));
  }
  int id, ed;
  for(int i = 1; i <= n; i ++ ){
    id = -1,ed=-1;
    for(auto x : T[i]){
      if(id == -1 || d[x.fi] < d[id]){
        id = x.fi;
        ed = x.se;
      }
    }
    if(d[id] > d[i]){
      cout << -1;
      return 0;
    }
    c[ed] = d[i];
    R[i].push_back(id);
    R[id].push_back(i);
  }
  for(int i = 1; i <= n; i ++ ){
    if(b[i]==-1){
      b[i]=0;
      dfs(i);
    }
  }
  for(int i = 1; i <= n; i ++ ){
    if(b[i]==0){
      cout << "W";
    }
    else{
      cout << "B";
    }
  }
  cout << "\n";
  for(int i = 1; i <= m ; i ++ ){
    if(c[i]==0) c[i]=(int)1e9;
    cout << c[i] << "\n";
  }
  return 0;
}
