#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e5 + 1;
const long double EPS = 1e-9;
const long long MOD = (long long)1e9 + 7;
const long long MAX = 1000 * 1000 * 1000;
const long long INF = (long long)1e9 + 10;
const long double PI = acosl(-1);
const int N = (int)1e6 + 2;
int d[N];
bool used[N];
struct Edge {
  int v, u, w, idx;
};
vector<Edge> g[N];
int answer[N];
int color[N];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    g[v].push_back({v, u, 0, i});
    g[u].push_back({u, v, 0, i});
  }
  set<pair<int, int>> vs;
  for (int i = 0; i < n; i++) {
    vs.insert({d[i], i});
  }
  while (!vs.empty()) {
    auto tmp = *vs.begin();
    int v = tmp.second;
    vs.erase(vs.begin());
    bool fnd = false;
    for (auto& e : g[v]) {
      int u = e.u;
      if (used[u]) {
        fnd = true;
        color[v] = 3 - color[u];
        answer[e.idx] = d[v];
        break;
      }
    }
    if (fnd) {
      used[v] = true;
      continue;
    }
    for (auto& e : g[v]) {
      int u = e.u;
      if (d[u] == d[v]) {
        color[v] = 1;
        color[u] = 2;
        fnd = true;
        answer[e.idx] = d[v];
        used[v] = used[u] = true;
      }
    }
    if (!fnd) {
      cout << -1 << endl;
      return;
    }
  }
  string colors;
  for (int i = 0; i < n; i++) {
    if (color[i] == 1) {
      colors += 'W';
    } else {
      assert(color[i] == 2);
      colors += 'B';
    }
  }
  cout << colors << endl;
  for (int i = 0; i < m; i++) {
    if (answer[i] == 0) {
      cout << MAX << "\n";
    } else {
      cout << answer[i] << "\n";
    }
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
