#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<tuple<int, int, int>> G[200010];
char BW[200010];
map<pair<int, int>, int> edge;
int ans[200010];
int main() {
  int N, M, U, V, dis;
  cin >> N >> M;
  vector<int> D(N);
  vector<pair<int, int>> Ds(N);
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    Ds[i] = {D[i], i};
  }
  sort(Ds.begin(), Ds.end());
  vector<pair<int, int>> Vs(M);
  for (int i = 0; i < M; i++) {
    cin >> U >> V;
    U--;
    V--;
    G[U].push_back(make_tuple(D[V], V, -1));
    G[V].push_back(make_tuple(D[U], U, -1));
    edge.insert({{U, V}, 0});
    edge.insert({{V, U}, 0});
    Vs[i] = {U, V};
  }
  for (int i = 0; i < N; i++) sort(G[i].begin(), G[i].end());
  int gs, fir, sec, thi, s, t;
  for (int x = 0; x < N; x++) {
    int i = Ds[x].second;
    dis = Ds[x].first;
    gs = G[i].size();
    tie(fir, sec, thi) = G[i][0];
    if (D[sec] < dis) {
      edge[{i, sec}] = dis - D[sec];
      edge[{sec, i}] = dis - D[sec];
      BW[i] = BW[sec];
      for (int g = 1; g < gs; g++) {
        t = get<1>(G[i][g]);
        edge[{i, t}] = 1000000000, edge[{t, i}] = 1000000000;
      }
    } else if (D[sec] == dis) {
      edge[{i, sec}] = dis;
      edge[{sec, i}] = dis;
      if (BW[i] == 0) {
        if (BW[sec] != 'B')
          BW[i] = 'B', BW[sec] = 'W';
        else
          BW[i] = 'W';
      } else if (BW[sec] == 0) {
        if (BW[i] == 'B')
          BW[sec] = 'W';
        else
          BW[sec] = 'B';
      }
      for (int g = 1; g < gs; g++) {
        t = get<1>(G[i][g]);
        if (edge[{i, t}] != dis)
          edge[{i, t}] = 1000000000, edge[{t, i}] = 1000000000;
      }
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << BW[i];
  }
  cout << endl;
  for (int i = 0; i < M; i++) {
    cout << edge[Vs[i]] << endl;
  }
}
