#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e5 + 5;

vector<int> gr[maxn], tr[maxn];
int N, M, col[maxn];
int U[maxn], V[maxn];
int w[maxn], d[maxn];
bool in[maxn];
int p[maxn];

void dfs(int u)
{
  for(int v : tr[u]) if(col[v] == -1){
    col[v] = col[u] ^ 1;
    dfs(v);
  }
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> M;
  for(int i = 1; i <= N; ++i)
    cin >> d[i];
  for(int i = 1; i <= M; ++i){
    cin >> U[i] >> V[i];
    gr[U[i]].eb(i); gr[V[i]].eb(i);
  }
  fill(w + 1, w + 1 + M, 1e9);
  for(int i = 1; i <= N; ++i){
    p[i] = -1;
    for(int id : gr[i]){
      int v = U[id] + V[id] - i;
      if(p[i] == -1 || d[p[i]] > d[v]){
        p[i] = v;
      }
    }
    if(d[i] < d[p[i]]){
      cout << -1;
      return 0;
    }
    tr[i].eb(p[i]);
    tr[p[i]].eb(i);
    for(int id : gr[i]){
      int v = U[id] + V[id] - i;
      if(v == p[i]){
        w[id] = d[i];
        break;
      }
    }
  }
  fill(col + 1, col + 1 + N, -1);
  for(int i = 1; i <= N; ++i){
    if(col[i] == -1){
      col[i] = 0;
      dfs(i);
    }
  }
  for(int i = 1; i <= N; ++i){
    cout << (col[i] ? 'B' : 'W');
  }
  cout << '\n';
  for(int i = 1; i <= M; ++i)
    cout << w[i] << '\n';
}
