#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Edge {
  int to, weight;
  Edge(int t, int w) :to(t), weight(w) {}
};

struct Graph {
  vector<vector<Edge>> edges;

  Graph(int N) :edges(N) {}

  void addEdge(int a, int b) { addEdge(a, b, 1); }

  void addEdge(int a, int b, int w) {
    edges[a].emplace_back(b, w);
  }
};

int main() {
  int N, M; cin >> N >> M;
  vector<pair<int, int>> Weights;
  vector<int> D(N);
  rep(i, N) {
    cin >> D[i];
    Weights.emplace_back(D[i], i);
  }

  Graph G(N);
  rep(i, M) {
    int x, y; cin >> x >> y;
    x--; y--;
    G.addEdge(x, y, i);
    G.addEdge(y, x, i);
  }

  sort(Weights.begin(), Weights.end());

  vector<int> ans(M, 1e9);
  vector<int> color(N, -1);
  rep(i, N) {
    int d = Weights[i].first, now = Weights[i].second;
    if (color[now] != -1) continue;

    for (Edge e : G.edges[now]) {
      if (color[e.to] != -1) {
        color[now] = color[e.to] ^ 1;
        ans[e.weight] = d;
        break;
      }
      else if (D[e.to] == d) {
        color[now] = 0;
        color[e.to] = 1;
        ans[e.weight] = d;
        break;
      }
    }

    if (color[now] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }

  rep(i, N) {
    if (color[i]) cout << "W";
    else cout << "B";
  }
  cout << endl;
  rep(i, M) {
    cout << ans[i] << endl;
  }
}