#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, num;
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> D;
  int dd[N];
  vector<int> C(M, -1);
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    dd[i] = d;
    D.push_back({d, i});
  }
  vector<edge> G[N];
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back({v, i});
    G[v].push_back({u, i});
  }
  sort(D.begin(), D.end());
  vector<int> c(N, -1);
  for (int i = 0; i < N; i++) {
    if (c[i] != -1) continue;
    int now = D[i].second;
    int cnt = D[i].first;
    for (int j = 0; j < G[now].size(); j++) {
      if (dd[G[now][j].to] == cnt) {
        if (c[G[now][j].to] != -1) {
          c[now] = 1 - c[G[now][j].to];
          C[G[now][j].to] = cnt;
          break;
        } else {
          c[now] = 0;
          c[G[now][j].to] = 1;
          C[G[now][j].to] = cnt;
          break;
        }
      } else if (dd[G[now][j].to] < cnt) {
        c[now] = 1 - c[G[now][j].to];
        C[G[now][j].to] = cnt - dd[G[now][j].to];
        break;
      }
    }
    if (c[now] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (c[i])
      cout << 'W';
    else
      cout << 'B';
  }
  for (int i = 0; i < M; i++) {
    if (C[i] == -1)
      cout << 1000000000 << endl;
    else
      cout << C[i] << endl;
  }
  return 0;
}
