#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const long double eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
int p = 0;
int D[N];
vector<pair<int, int> > g[N];
int w[200000];
bool used[N];
char col[N];
void bfs(int n) {
  queue<int> q;
  used[0] = true;
  col[0] = 'B';
  q.push(0);
  p++;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto it : g[u]) {
      if (used[it.first]) {
        continue;
      }
      col[it.first] = (col[u] == 'B' ? 'W' : 'B');
      w[it.second] = D[p++];
      used[it.first] = true;
      q.push(it.first);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    cin >> D[i];
  }
  sort(D, D + n);
  if (D[0] != D[1]) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = (0); i < (m); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  for (int i = (0); i < (m); i++) {
    w[i] = 1000000000;
  }
  bfs(n);
  for (int i = (0); i < (n); i++) {
    cout << col[i];
  }
  cout << "\n";
  for (int i = (0); i < (m); i++) {
    cout << w[i] << "\n";
  }
  return 0;
}
