#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename X>
struct Edge {
  int from;
  int to;
  X cost;
  int idx;
  Edge() = default;
  Edge(int from, int to, int idx, X cost)
      : from(from), to(to), idx(idx), cost(cost) {}
};
template <typename X>
struct Node {
  int idx;
  vector<Edge<X>> edge;
  int color;
  int d;
  Node() = default;
  explicit Node(int idx) : idx(idx) {}
};
template <typename X>
class Graph {
 private:
  int n;
  int m;
  vector<Node<X>> node;
  void Init_Node() {
    for (int i = 0; i < n; ++i) node.emplace_back(i);
  }

 public:
  explicit Graph(int n) : n(n) { Init_Node(); }
  Graph(int n, int m, vector<int> from, vector<int> to) : n(n), m(m) {
    Init_Node();
    for (int i = 0; i < m; ++i) {
      add_edge(from[i], to[i], i);
      add_edge(to[i], from[i], i);
    }
  }
  Graph(int n, int m, vector<int> from, vector<int> to, vector<X> cost)
      : n(n), m(m) {
    Init_Node();
    for (int i = 0; i < m; ++i) {
      add_edge(from[i], to[i], i, cost[i]);
      add_edge(to[i], from[i], i, cost[i]);
    }
  }
  void add_edge(int from, int to, int idx, X cost = 1) {
    node[from].edge.emplace_back(from, to, idx, cost);
  }
  void Build(vector<int> a) {
    for (int i = 0; i < n; ++i) {
      node[i].d = a[i];
      node[i].color = 0;
    }
  }
  void solve() {
    vector<int> res(m, -1);
    using pi = pair<int, int>;
    priority_queue<pi> q;
    for (int i = 0; i < n; ++i) q.push({-node[i].d, i});
    while (!q.empty()) {
      pi p = q.top();
      q.pop();
      int x = -p.first, v = p.second;
      for (auto next : node[v].edge) {
        int w = next.to;
        if (node[w].color != 0) {
          node[v].color = -node[w].color;
          res[next.idx] = node[v].d;
          break;
        } else {
          if (node[w].d == node[v].d) {
            node[v].color = 1;
            node[w].color = -1;
            res[next.idx] = node[v].d;
          }
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      if (node[i].color == 0) {
        cout << -1 << "\n";
        return;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << (node[i].color == 1 ? "B" : "W");
    }
    cout << "\n";
    for (int i = 0; i < m; ++i) {
      cout << (res[i] == -1 ? 1000000000 : res[i]) << "\n";
    }
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> u(m), v(m);
  for (int i = 0; i < m; ++i) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
  }
  Graph<int> gp(n, m, u, v);
  gp.Build(a);
  gp.solve();
  return 0;
}
