#include<bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;

vi D;
vvpi G;
vi vist, C;

void dfs(int x, int val, int col) {
  vist[x] = col;
  for (auto it : G[x]) {
    int y = it.first;
    if (D[y] == val and vist[y] == -1) {
      C[it.second] = val;
      dfs(y, val, col^1);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n , m;
  cin >> n >> m;
  D = vi(n);
  G = vvpi(n);
  vpi V(n);
  for (int i = 0; i < n; ++i) {
    cin >> D[i];
    V[i] = pi(D[i], i);
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    G[x].push_back(pi(y,i));
    G[y].push_back(pi(x,i));
  }
  sort(V.begin(), V.end());
  bool pots = true;
  C = vi(m, -1);
  vist = vi(n, -1);
  for (int i = 0; i < n; ++i) {
    int x = V[i].second;
    if (vist[x] != -1) continue;
    int minval = D[x] + 1;
    int minar = -1;
    int mincol = -1;
    int contt = 0;
    for (auto it : G[x]) {
      int y = it.first;
      if (D[y] < minval) {
        minar = it.second;
        minval = D[y];
        mincol = vist[y];
      }
      if (D[y] == D[x]) ++contt;
    }
    if (minval > D[x]) {
      pots = false;
      break;
    }
    else if (contt) {
      dfs(x, D[x], 0);
    }
    else {
      C[minar] = D[x];
      vist[x] = mincol^1;
    }
  }
  if (!pots) {
    cout << -1 << '\n';
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (vist[i]) cout << 'B';
    else cout << 'W';
  }
  cout << '\n';
  for (int i = 0; i < m; ++i) {
    if (C[i] == -1) cout << 1000000000 << '\n';
    else cout << C[i] << '\n';
  }

}
