#include <bits/stdc++.h>
using namespace std;
long long int INF = 3e18;
const long long fact_table = 800008;
double Pi = 3.1415926535897932384626;
vector<pair<long long, long long> > G[550010];
vector<pair<long long, long long> > G2[550010];
priority_queue<long long> pql;
priority_queue<pair<long long, long long> > pqp;
priority_queue<long long, vector<long long>, greater<long long> > pqls;
long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
long long mod = 1000000007;
long long rui(long long number1, long long number2) {
  if (number2 == 0) {
    return 1;
  } else {
    long long number3 = rui(number1, number2 / 2);
    number3 *= number3;
    number3 %= mod;
    if (number2 % 2 == 1) {
      number3 *= number1;
      number3 %= mod;
    }
    return number3;
  }
}
long long gcd(long long number1, long long number2) {
  if (number1 > number2) {
    swap(number1, number2);
  }
  if (number1 == 0 || number1 == number2) {
    return number2;
  } else {
    return gcd(number2 % number1, number1);
  }
}
void YES(bool condition) {
  if (condition) {
    cout << "YES"
         << "\n";
    ;
  } else {
    cout << "NO"
         << "\n";
    ;
  }
  return;
}
void Yes(bool condition) {
  if (condition) {
    cout << "Yes"
         << "\n";
    ;
  } else {
    cout << "No"
         << "\n";
    ;
  }
  return;
}
long long n, m, num, sum, a, b, c, d, e, g, h, i, j, q, r, l;
long long k;
long long ans;
long long x[500005], y[200005], z[200005];
long long w[5005];
bool edge_use[500005];
long long edge_cost[500005];
bool used[3005];
pair<long long, long long> table[500005];
long long c_table[500005];
long long p[500005], ran[500005];
vector<pair<pair<long long, long long>, long long> > edge;
vector<pair<long long, long long> > que;
void edge_put(long long v1, long long v2, long long cost) { return; }
long long find(long long x) {
  if (p[x] == x) {
    return x;
  } else {
    return p[x] = find(p[x]);
  }
}
void unite(long long x, long long y, long long idx) {
  edge_use[idx] = true;
  G2[x].push_back(pair<long long, long long>(y, idx));
  G2[y].push_back(pair<long long, long long>(x, idx));
  edge.push_back(pair<pair<long long, long long>, long long>(
      pair<long long, long long>(x, y), idx));
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (ran[x] < ran[y]) {
    p[x] = y;
  } else {
    p[y] = x;
    if (ran[x] == ran[y]) ran[x]++;
  }
}
void dfs(long long v, long long cost, long long color) {
  c_table[v] = color;
  used[v] = true;
  for (long long i = 0; i < G2[v].size(); i++) {
    long long nv = G2[v][i].first;
    long long edge_idx = G2[v][i].second;
    if (used[nv]) continue;
    if (x[nv - 1] == x[v - 1]) {
      que.push_back(pair<long long, long long>(nv, 3 - color));
      edge_cost[edge_idx] = x[nv - 1];
    } else if (x[v - 1] > x[nv - 1]) {
      edge_cost[edge_idx] = INF;
    } else {
      edge_cost[edge_idx] = x[nv - 1] - x[v - 1];
    }
    dfs(nv, x[nv - 1], color);
  }
  return;
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (long long i = 1; i <= n; i++) {
    p[i] = i;
  }
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    y[i] = a;
    z[i] = b;
    G[a].push_back(pair<long long, long long>(b, i));
    G[b].push_back(pair<long long, long long>(a, i));
  }
  long long neededge = n - 1;
  for (long long i = 1; i <= n; i++) {
    long long mycost = x[i - 1];
    bool dame = true;
    long long connect = -1;
    long long edge_idx = -1;
    for (long long j = 0; j < G[i].size(); j++) {
      long long yourcost = x[G[i][j].first - 1];
      if (yourcost <= mycost) {
        dame = false;
        if ((find(i) != find(G[i][j].first)) && neededge > 0) {
          connect = G[i][j].first;
          edge_idx = G[i][j].second;
        }
      }
    }
    if (connect != -1) {
      unite(i, connect, edge_idx);
      neededge--;
    }
    if (dame) {
      cout << -1 << "\n";
      ;
      return 0;
    }
  }
  for (long long i = 0; i < m; i++) {
    if (neededge <= 0) break;
    if (find(z[i]) != find(y[i])) {
      unite(z[i], y[i], i);
      neededge--;
    }
  }
  for (long long i = 0; i < edge.size(); i++) {
    long long v1 = (edge[i].first).first;
    long long v2 = (edge[i].first).second;
    long long idx = (edge[i].second);
    if (x[v1 - 1] == x[v2 - 1]) {
      que.push_back(pair<long long, long long>(v1, 1));
      que.push_back(pair<long long, long long>(v2, 2));
      used[v1] = true;
      used[v2] = true;
      edge_cost[idx] = x[v1 - 1];
    }
  }
  while (que.size() != 0) {
    pair<long long, long long> p = que.back();
    que.pop_back();
    long long color = p.second;
    long long v = p.first;
    dfs(v, x[v - 1], color);
  }
  for (long long i = 1; i <= n; i++) {
    if (c_table[i] == 1) {
      cout << ("B");
      ;
    } else if (c_table[i] == 2) {
      cout << ("W");
      ;
    } else {
      cout << ("W");
      ;
    }
  }
  cout << endl;
  ;
  for (long long i = 0; i < m; i++) {
    if (edge_cost[i] == 0 || edge_cost[i] == INF) {
      cout << 1000000000 << "\n";
      ;
    } else {
      cout << edge_cost[i] << "\n";
      ;
    }
  }
  return 0;
}
