#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

typedef pair<int,int> P;
vector<P> g[100010];
int d[100010];

int main(){
   int n,m; scanf("%d%d",&n,&m);
   rep(i,0,n)scanf("%d",&d[i]);
   rep(i,0,m){
      int u,v; scanf("%d%d",&u,&v);
      u--; v--;
      g[u].push_back({v,i});
      g[v].push_back({u,i});
   }
   map<int,vector<int>> mp;
   rep(i,0,n)mp[d[i]].push_back(i);
   vector<int> col(n,-1),res(m,1e9);
   for(auto p:mp){
      int val=p.first; vector<int> vs=p.second;
      for(auto v:vs)if(col[v]==-1){
         bool f=1;
         for(auto e:g[v]){
            int nxt=e.first;
            if(d[v]<d[nxt])continue;
            f=0; res[e.second]=val;
            if(col[nxt]==-1){
               col[v]=0; col[nxt]=1;
            }
            else col[v]=col[nxt]^1;
            break;
         }
         if(f){
            printf("-1\n");
            return 0;
         }
      }
   }
   rep(i,0,n)printf(col[i]==0?"W":"B"); puts("");
   rep(i,0,m)printf("%d\n",res[i]);
   return 0;
}