#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

pll pllminmax(ll i,ll j){
  return pll(min(i,j),max(i,j));
}

void solve(long long N, long long M, std::vector<long long> D, std::vector<long long> U, std::vector<long long> V){
  vector<vector<ll>> mp(N);
  map<pll,ll> weight;
  vector<char> bw(N,0);
  REP(M){
    mp[U[i]].push_back(V[i]);
    mp[V[i]].push_back(U[i]);
  }
  vector<pll> d(N);
  REP(N){
    d[i]=pll(D[i],i);
  }
  sort(d.begin(),d.end());
  ll i=0;
  if(d[0].first!=d[1].first){
    cout<<-1<<endl;
    return;
  }
  weight[pllminmax(d[0].second,d[1].second)]=d[0].first;
  bw[d[0].second]='B';
  bw[d[1].second]='W';
  i=2;
  while(i<N){
    ll cur=d[i].second;
    ll curd=d[i].first;
    ++i;
    bool f=false;
    for (auto &&j : mp[cur])
    {
      if(bw[j]!=0&&D[cur]!=D[j]){
        bw[cur]=bw[j];
        weight[pllminmax(cur,j)]=D[cur]-D[j];
        f=true;
        break;
      }
    }
    if(f){
      continue;
    }
    ll next=d[i].second;
    ll nextd=d[i].first;
    ++i;
    if(nextd!=curd){
      cout<<-1<<endl;
      return;
    }
    bw[cur]='B';
    bw[next]='W';
    weight[pllminmax(cur,next)]=curd;
  }
  cout<<string(bw.begin(),bw.end())<<endl;
  REP(M){
    if(weight.count(pllminmax(U[i],V[i]))){
      cout<<weight[pllminmax(U[i],V[i])]<<endl;
    }else{
      cout<<1000000000<<endl;
    }
  }
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> D(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&D[i]);
    }
    std::vector<long long> U(M);
    std::vector<long long> V(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&U[i]);
        scanf("%lld",&V[i]);
        --U[i];
        --V[i];
    }
    solve(N, M, std::move(D), std::move(U), std::move(V));
    return 0;
}
