#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
const int N = 1e5 + 5;
int n, m;
int d[N];
int used[N];
struct edge
{
    int u, v, index;
    edge(int a, int b, int c)
    {
        u = a;
        v = b;
        index = c;
    }
};
struct compare 
{
    bool operator() (const edge &lhs, const edge &rhs) const
    {
        return mp(lhs.u, lhs.v) < mp(rhs.u, rhs.v);
    }
};
set<  edge , compare> edges;
int color[N];
int w[2*N];
vector < vi > graph(N);
int main()
{
    she_told_me_dont_worry
    cin>>n>>m;
    int i;
    map< int , vi > scores;
    FOR0(i, n)
    {
        cin>>d[i];
        used[i] = 0;
        color[i] = -1;
    }
    FOR0(i, m)
    {
        w[i] = 1e9;
        int u, v;
        cin>>u>>v;
        u--;
        v--;
        graph[u].pb(v);
        graph[v].pb(u);
        if( u > v) swap(u, v);
        edges.insert( edge(u, v, i) );
    }
    queue< int > q;
    FOR0(i, n)
    {
        int u = i;
        int j , si = graph[u].size();
        int cur = 0;
        FOR0(j, si)
        {
            int v = graph[i][j];
            if(used[v]) continue;
            if(d[u] == d[v])
            {
                if(!cur)
                    q.push(u);
                q.push(v);
                used[u] = 1;
                used[v] = 1;
                color[u] = 0;
                color[v] = 1;
                set<  edge , compare>::iterator it = edges.find(edge(u, v, -1));
                w[it->index] = d[u];
                cur++;
            }
        }
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        int j, si = graph[u].size();
        FOR0(j, si)
        {
            int v = graph[u][j];
            if(!used[v] && d[v] >= d[u])
            {
                set<  edge , compare>::iterator it = edges.find(edge(u, v, -1));
                w[it->index] = d[v];
                used[v] = 1;
                color[v] = 1-color[u];
                q.push(v);
            }
            
        }
    }
    bool is = true;
    FOR0(i, n)
    {
        if(!used[i]) 
        {
            is = false;
            break;
        }
    }
    if(!is)
    {
        cout<<-1<<endl;
    }
    else
    {
        FOR0(i, n)
        {
            if(!color[i]) cout<<"W";
            else cout<<"B";
        }
        cout<<endl;
        FOR0(i, m)
            cout<<w[i]<<endl;
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}