#include <bits/stdc++.h>
using namespace std;
struct unionfind {
  vector<int> data;
  vector<int> size;
  unionfind(int n) {
    for (int i = 0; i < n; i++) {
      data.push_back(i);
      size.push_back(1);
    }
  }
  int find(int x) {
    if (data[x] == x) return x;
    return data[x] = find(data[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    data[x] = y;
    size[y] += size[x];
    return true;
  }
  bool check(int x, int y) { return (find(x) == find(y)); }
  int get_size(int x) {
    int X = find(x);
    return size[X];
  }
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> D(N);
  long long mini = 10000000000;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &D[i]);
    mini = min(mini, D[i]);
  }
  unionfind uf(N);
  vector<vector<int>> E(N, vector<int>());
  map<pair<int, int>, int> mp;
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    if (D[a] == mini && D[b] == mini) uf.unite(a, b);
    E[a].push_back(b);
    E[b].push_back(a);
    mp[make_pair(a, b)] = i;
    mp[make_pair(b, a)] = i;
  }
  vector<int> L;
  queue<int> Q;
  vector<bool> used(N, false);
  for (int i = 0; i < N; i++) {
    if (D[i] != mini) continue;
    L.push_back(i);
    if (uf.get_size(i) == 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> ansE(M, 1000000000);
  vector<char> ansC(N, 'B');
  while (Q.size() != 0 || L.size() != 0) {
    if (Q.size() == 0) {
      if (used[L.back()] == false) Q.push(L.back());
      used[L.back()] = true;
      L.pop_back();
      continue;
    }
    int from = Q.front();
    Q.pop();
    for (int i = 0; i < E[from].size(); i++) {
      int to = E[from][i];
      if (used[to]) continue;
      if (D[to] == D[from]) {
        if (ansC[from] == 'B')
          ansC[to] = 'W';
        else
          ansC[to] = 'B';
        ansE[mp[make_pair(from, to)]] = D[to];
        used[to] = true;
        Q.push(to);
      }
      if (D[to] > D[from]) {
        ansC[to] = ansC[from];
        ansE[mp[make_pair(from, to)]] = D[to] - D[from];
        used[to] = true;
        Q.push(to);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ansC[i];
  }
  cout << endl;
  for (int i = 0; i < M; i++) {
    cout << ansE[i] << endl;
  }
  return 0;
}
