#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const long long MOD = 998244353;
const long long MAX = 1000001;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a > b) {
    return b;
  }
  return a;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  if (a < b) {
    return gcd(b, a);
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct edge {
  long long ind;
  long long fr;
  long long to;
  long long d;
};
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> D(N + 1);
  for (long long i = 1; i <= N; i++) cin >> D[i];
  vector<pair<long long, long long>> Dp(N + 1);
  for (long long i = 1; i <= N; i++) Dp[i] = {D[i], i};
  sort(++Dp.begin(), Dp.end());
  vector<vector<edge>> g(N + 1);
  for (long long i = 1; i <= M; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back({i, u, v, 0});
    g[v].push_back({i, v, u, 0});
  }
  long long b = 1;
  for (long long v = 1; v <= N; v++) {
    long long bb = 0;
    for (edge e : g[v]) {
      long long w = e.to;
      if (D[w] <= D[v]) {
        bb = 1;
      }
    }
    if (bb == 0) {
      b = 0;
      break;
    }
  }
  if (b == 0) {
    cout << -1;
  } else {
    vector<long long> s(N + 1, -1);
    vector<long long> C(M + 1, -1);
    for (long long i = 1; i <= N; i++) {
      long long v = Dp[i].second;
      if (s[v] != -1) {
        continue;
      }
      long long u = 0;
      for (edge e : g[v]) {
        long long w = e.to;
        if (s[w] != -1) {
          u = w;
          break;
        }
      }
      if (u != 0) {
        s[v] = (s[u] + 1) % 2;
        for (edge e : g[v]) {
          long long w = e.to;
          if (w == u) {
            C[e.ind] = D[v];
          } else if (s[w] != -1) {
            C[e.ind] = 1000000000;
          }
        }
      }
      if (u == 0) {
        s[v] = 0;
        for (edge e : g[v]) {
          long long w = e.to;
          if (D[v] == D[w]) {
            s[w] = 1;
            C[e.ind] = D[v];
            break;
          }
        }
      }
    }
    for (long long i = 1; i <= N; i++) {
      if (s[i] == 0) {
        cout << 'B';
      } else {
        cout << 'W';
      }
    }
    cout << endl;
    for (long long i = 1; i <= M; i++) {
      cout << C[i] << endl;
    }
  }
  system("PAUSE");
}
