#include <bits/stdc++.h>
const double PI = 3.14159265358979323846;
using namespace std;
const double EPS = 1e-9;
const long long INF = 10e17;
std::istream &operator>>(std::istream &in, set<long long> &o) {
  long long a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
vector<vector<int>> create_edges(int n,
                                 vector<pair<long long, long long>> &edges) {
  vector<vector<int>> g(n);
  for (pair<long long, long long> p : edges) {
    int a = p.first;
    int b = p.second;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < (n); ++i) sort(g[i].begin(), g[i].end());
  return g;
}
int get_pi(int i, vector<vector<int>> &g, vector<long long> &ds) {
  long long mi = INT_MAX;
  for (int j : g[i]) {
    mi = min(mi, ds[j]);
  }
  for (int j : g[i]) {
    if (ds[j] == mi) return j;
  }
  __throw_runtime_error("konaide");
}
pair<long long, long long> cp(int i, int j) { return {min(i, j), max(i, j)}; }
vector<vector<int>> create_g2(int n, vector<int> &ps) {
  set<pair<long long, long long>> es;
  for (int i = 0; i < (n); ++i) {
    es.insert(cp(i, ps[i]));
  }
  vector<pair<long long, long long>> eds;
  for (pair<long long, long long> p : es) eds.push_back(p);
  return create_edges(n, eds);
}
void dfs(int i, char c, vector<char> &colors, vector<vector<int>> &edges) {
  if (colors[i] != ' ') return;
  colors[i] = c;
  for (int j : edges[i]) {
    dfs(j, c == 'W' ? 'B' : 'W', colors, edges);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> ds(n);
  for (int i = 0; i < (n); ++i) cin >> ds[i];
  vector<pair<long long, long long>> g_edges(m);
  for (pair<long long, long long> &p : g_edges)
    cin >> p.first >> p.second, p.first--, p.second--;
  vector<vector<int>> g = create_edges(n, g_edges);
  for (int i = 0; i < (n); ++i) {
    bool ok = [&] {
      for (int j : g[i]) {
        if (ds[i] >= ds[j]) return true;
      }
      return false;
    }();
    if (!ok) {
      cout << -1 << endl;
      return 0;
      ;
    }
  }
  vector<int> ps(n, -1);
  for (int i = 0; i < (n); ++i) ps[i] = get_pi(i, g, ds);
  vector<vector<int>> g2 = create_g2(n, ps);
  vector<char> colors(n, ' ');
  for (int i = 0; i < (n); ++i) dfs(i, 'W', colors, g2);
  for (char c : colors) cout << c;
  cout << endl;
  map<pair<long long, long long>, long long> ans;
  for (int i = 0; i < (n); ++i) {
    if (ans.find(cp(i, ps[i])) == ans.end()) {
      ans[cp(i, ps[i])] = ds[i];
    } else {
      __throw_runtime_error("konaide");
      ans[cp(i, ps[i])] = min(ans[cp(i, ps[i])], ds[i]);
    }
  }
  for (pair<long long, long long> p : g_edges) {
    pair<long long, long long> index = cp(p.first, p.second);
    if (ans.find(index) == ans.end()) ans[index] = 1e8;
  }
  for (pair<long long, long long> p : g_edges) {
    pair<long long, long long> index = cp(p.first, p.second);
    cout << ans[index] << endl;
  }
}
