/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#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;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 100010;
int n,m;
int d[MAXN],x[2*MAXN],y[2*MAXN],deg[MAXN];
vi adj[MAXN];
int done[MAXN],ans[MAXN],col[MAXN];
map<pi,int> mp;

void dfs(int s, int p, int c){
  col[s] = c;
  done[s] = 1;
  vi v; 
  for(auto t:adj[s]){
    if(t!=p && !done[t] ){
      col[t] = (c^1);
      done[t] = 1;
      v.pb(t);
    }
  }
  for(auto t:v){
    dfs(t,s,col[t]);
  }
}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool Same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> m;
  int root = 1,mn = 1e9;
  for(int i=1;i<=n;i++){cin >> d[i];
    if(d[i]<mn){
      mn = d[i];
      root = i;
    }
  }
  for(int i=1;i<=m;i++){
    cin >> x[i] >> y[i];
    if(x[i]>y[i])swap(x[i],y[i]);
    mp[{x[i],y[i]}]=i;
    ans[i] = max(d[x[i]],d[y[i]]);
    adj[x[i]].pb(y[i]);
    adj[y[i]].pb(x[i]);
    deg[x[i]]++;
    deg[y[i]]++;
  }
  dfs(root,-1,0);
  // for(int i=1;i<=n;i++){
  //   cout << col[i] << endl;
  // }
  // cout << root << endl;
  // UnionFindTree uf(n+10);
  // for(int i=1;i<=m;i++){
  //   if(col[x[i]]==col[y[i]]){
  //     uf.unite(x[i],y[i]);
  //   }
  // }
  for(int i=1;i<=n;i++){
    int x = 1e9;
    for(auto t:adj[i]){
      if(col[t]!=col[i]){
        int u = i, v = t;
        if(u>v)swap(u,v);
        x=min(x,ans[mp[{u,v}]]);
      }
    }
    // cout << i << " " << x << endl;
    if(x!=d[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  for(int i=1;i<=n;i++){
    if(col[i])cout<<"B";
    else cout<<"W";
  }
  cout<<endl;
  for(int i=1;i<=m;i++){
    cout<<ans[i]<<endl;
  }

  // queue<int> q;
  // for(int i=1;i<=n;i++){
  //   if(deg[i]==1){
  //     q.push(i);
  //   }
  // }
  // while(!q.empty()){
  //   int s = q.front();q.pop();
  //   done[s] = 1;
  //   for(auto t:adj[s]){
  //     if(!done[t]){
  //       if(d[t]>d[s]){
  //         cout << -1 << endl;
  //         return 0;
  //       }
  //       int u = s;
  //       int v = t;
  //       if(u>v)swap(u,v);
  //       ans[mp[{u,v}]]=d[s];
  //       deg[t]--;
  //       if(deg[t]==1){
  //         q.push(t);
  //       }
  //     }
  //   }
  // }





return 0;
}
///....
