#include <bits/stdc++.h>
using namespace std;
int N, M;
int D[200010];
pair<int, int> O[200010];
vector<pair<int, int>> G[200010];
int ans[200010], dist[200010];
bool c[200010];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d", D + i);
    O[i] = {D[i], i};
  }
  sort(O, O + N);
  for (int i = 0; i < M; i++) {
    int U, V;
    scanf("%d%d", &U, &V);
    U--;
    V--;
    G[U].push_back({V, i});
    G[V].push_back({U, i});
  }
  for (int i = 0; i < M; i++) ans[i] = -1;
  for (int i = 0; i < N; i++) {
    int p = O[i].second;
    int d = O[i].first;
    bool isB = true;
    pair<int, int> q;
    for (auto e : G[p]) {
      int to = e.first;
      if (c[to] || (dist[to] && dist[to] < d)) {
        isB = false;
        q = e;
      }
    }
    if (isB) {
      c[p] = true;
    } else {
      c[p] = false;
      assert(ans[q.second] == -1);
      ans[q.second] = d - dist[q.first];
      dist[p] = d;
    }
  }
  int e9 = 1000000000;
  for (int i = 0; i < N; i++) {
  }
  for (int i = 0; i < M; i++) {
    if (ans[i] == -1) ans[i] = e9;
  }
  for (int i = 0; i < N; i++) {
    if (!c[i]) continue;
    int mindist = 1000000000;
    for (auto e : G[i]) {
      mindist = min(mindist, ans[e.second]);
    }
    if (mindist == 1000000000) {
      int d = D[i];
      for (auto e : G[i]) {
        int to = e.first;
        if (dist[to] >= d) {
          assert(ans[e.second] == 1000000000);
          ans[e.second] = d;
          dist[i] = d;
          break;
        }
      }
    } else if (mindist != D[i]) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    printf("%c", "WB"[c[i]]);
  }
  puts("");
  for (int i = 0; i < M; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
