import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

long maxcost = 1_000_000_000;
void solve(){
	int n = rint, m = rint;

	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i, rlong);

	Edge[] edges;
	foreach(j; 0 .. m){
		Node u = nodes[rint - 1], v = nodes[rint - 1];
		edges ~= new Edge(u, v);
		u.nodes ~= v, v.nodes ~= u;
	}

	foreach(nd; nodes){
		nd.nodes.sort!"(a.value!=b.value)?(a.value<b.value):(a.id<b.id)"();
		nd.parent = nd.nodes[0];
		if(nd.value < nd.parent.value){
			"-1".writeln;
			return;
		}
		if(nd.value == nd.parent.value && nd.id < nd.parent.id)
				nd.parent.color = 'W';
	}

	foreach(ed; edges){
		Node u = ed.node1, v = ed.node2;
		if(u.parent.id == v.id || u.id == v.parent.id){
			if(u.value == v.value) ed.value = u.value;
			else ed.value = abs(u.value - v.value);
		}
		else ed.value = maxcost;
	}

	nodes.map!(nd => nd.color).writeln;
	foreach(ed; edges) ed.value.writeln;

}

class Node{
	int id;
	Node parent;
	Node[] nodes;
	long value;
	char color = 'B';
	this(int id, long value){
		this.id = id, this.value = value;

	}
}

class Edge{
	Node node1, node2;
	long value;
	this(Node nd1, Node nd2){
		node1 = nd1, node2 = nd2;
	}
}