#include <bits/stdc++.h>
using namespace std;
class Edge {
 public:
  int to, index;
  Edge(int to, int index) {
    this->to = to;
    this->index = index;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> d(n);
  vector<pair<int, int> > v(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    v[i] = make_pair(d[i], i);
  }
  sort(v.begin(), v.end());
  vector<vector<Edge> > edges(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    edges[u].push_back(Edge(v, i));
    edges[v].push_back(Edge(u, i));
  }
  vector<int> ans(m, -1);
  for (int i = 0; i < n; ++i) {
    int a = v[i].second;
    bool ok = false;
    for (const Edge& e : edges[a]) {
      if (d[e.to] <= d[a]) {
        ans[e.index] = d[a];
        ok = true;
        break;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  string color(n, '.');
  for (int i = 0; i < n; ++i) {
    if (color[i] == '.') color[i] = 'B';
    for (const Edge& e : edges[i]) {
      if (ans[e.index] != -1) color[e.to] = 'B' ^ 'W' ^ color[i];
    }
  }
  cout << color << endl;
  for (int i = 0; i < m; ++i) {
    if (ans[i] == -1)
      cout << 1000000000 << endl;
    else
      cout << ans[i] << endl;
  }
  return 0;
}
