#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Edge {
  int to;
  T cost;
};
template <typename T>
struct WeightedGraph {
  int n;
  vector<vector<Edge<T>>> g;
  WeightedGraph(int n) : n(n) { g.resize(n); }
  void init(int n_) {
    n = n_;
    g.resize(n_);
  }
  void add_edge(int from, int to, T cost) {
    g[from].push_back((Edge<T>){to, cost});
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  int d[100002];
  pair<int, int> p[100002];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    p[i] = pair<int, int>(d[i], i);
  }
  sort(p, p + n);
  WeightedGraph<int> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g.add_edge(u, v, i);
    g.add_edge(v, u, i);
  }
  bool used[100002]{0};
  char c[100002];
  for (int i = 0; i < n; i++) c[i] = 'N';
  int l[200002];
  for (int i = 0; i < n; i++) {
    int u = p[i].second;
    used[u] = true;
    int les = 1000000000;
    for (Edge<int> e : g.g[u]) {
      int v = e.to;
      les = min(les, d[v]);
      if (used[v]) {
        if (d[v] == d[u] && c[v] == 'W' && c[u] == 'N') c[u] = 'B';
        if (c[u] == 'N') c[u] = 'W';
        if (c[v] != c[u])
          l[e.cost] = d[u];
        else
          l[e.cost] = max(1, d[u] - d[v]);
      }
    }
    if (c[u] == 'N' && les > d[u]) {
      cout << -1 << endl;
      return 0;
    }
    if (c[u] == 'N') c[u] = 'B';
  }
  for (int i = 0; i < n; i++) cout << c[i];
  cout << endl;
  for (int i = 0; i < m; i++) cout << l[i] << endl;
}
