#include <bits/stdc++.h>
using namespace std;
int N, M;
int D[100010], col[100010], dis[200020], deg[200020];
bool chk[100010];
vector<pair<int, int> > E[100010];
void dfs(int cur, int c) {
  if (chk[cur]) return;
  chk[cur] = true;
  col[cur] = c;
  for (pair<int, int> nxt : E[cur]) {
    if (chk[nxt.second]) continue;
    if (D[cur] == D[nxt.second]) {
      dis[nxt.first] = D[cur];
      dfs(nxt.second, 3 - c);
    } else {
      dis[nxt.first] = D[cur] - D[nxt.second];
      dfs(nxt.second, c);
    }
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> D[i];
  for (int i = 1; i <= M; i++) {
    int x, y;
    cin >> x >> y;
    if (D[x] >= D[y]) E[x].push_back({i, y});
    if (D[x] > D[y]) deg[y]++;
    if (D[y] >= D[x]) E[y].push_back({i, x});
    if (D[y] > D[x]) deg[x]++;
  }
  for (int i = 1; i <= N; i++) {
    if (deg[i] == 0) dfs(i, 1);
  }
  bool b = false, w = false;
  for (int i = 1; i <= N; i++) {
    if (!col[i]) {
      cout << -1;
      return 0;
    }
    if (col[i] == 1)
      b = true;
    else
      w = true;
  }
  if (!b || !w) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= N; i++) cout << (col[i] == 1 ? 'B' : 'W');
  cout << '\n';
  for (int i = 1; i <= M; i++) {
    cout << (dis[i] == 0 ? 1000000000 : dis[i]) << '\n';
  }
}
