#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

const int MAXN = 200001;
int n,m,d[MAXN],col[MAXN],ans[MAXN],good[MAXN];
vector<pair<int,int>> adj[MAXN];

void dfs(int s, int c){
    col[s]=c;
    for(auto t:adj[s]){
        if(col[t.first]==-1){
            ans[t.second]=d[t.first];
            dfs(t.first,c^1);
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&d[i]);
        col[i]=-1;
    }
    for(int i=0;i<m;i++){
        int x,y;
        ans[i]=1e9;
        scanf("%d%d",&x,&y);x--;y--;
        if(d[x]==d[y]){
            good[x]=1;
            adj[x].push_back({y,i});
            adj[y].push_back({x,i});
        }
        else if(d[x]>d[y]){
            adj[y].push_back({x,i});
        }
        else {
            adj[x].push_back({y,i});
        }
    }
    for(int i=0;i<n;i++){
        if(good[i]&&col[i]==-1){
            dfs(i,0);
        }
    }
    for(int i=0;i<n;i++){
        if(col[i]==-1){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        cout<<"BW"[col[i]];
    }
    cout<<endl;
    for(int i=0;i<m;i++){
        printf("%d\n",ans[i]);
    }

}