#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

struct Edge {
  int to;
  int id;
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& g, int u, int v, int id) {
  g[u].push_back(Edge{v,id});
  g[v].push_back(Edge{u,id});
}

int main()
{
  int n,m;
  cin>>n>>m;
  vector<int> d;
  vector<tuple<int,int>> dt;
  for(auto&& i:irange(0,n)){
    int e;
    cin>>e;
    d.push_back(e);
    dt.emplace_back(e,i);
  }
  boost::sort(dt);
  Graph g(n);
  for(auto&& i:irange(0,m)) {
    int u,v;
    cin>>u>>v;
    --u;--v;
    add_edge(g,u,v,i);
  }
  vecint clr(n,-1);
  vecint w(m,1000000000);
  bool valid = true;
  for(auto&& t:dt) {
    int di,i;
    tie(di,i) = t;
    assert(di == d[i]);
    int md = 1e9+1;
    int idxto = -1;
    int idxe = -1;
    for(auto&& e:g[i]) {
      if (d[e.to] > di) continue;
      if (d[e.to] == md) {
        if (e.to < idxto) {
          idxto = e.to;
          idxe = e.id;
        }
      }
      if (d[e.to] < md) {
        md = d[e.to];
        idxto = e.to;
        idxe = e.id;
      }
    }
    if (idxto < 0) {
      valid = false;
      break;
    }
    if (clr[idxto] == -1) {
      clr[i] = 0;
    } else {
      clr[i] = 1-clr[idxto];
    }
    w[idxe] = di;
  }
  if (valid) {
    for(auto&& e:clr) {
      if(e==0) {
        cout<<'B';
      }else{
        cout<<'W';
      }
    }
    cout<<endl;
    for(auto&& e:w) {
      cout<<e<<endl;
    }
  } else {
    cout<<-1<<endl;
  }
  return 0;
}
