/* 算法竞赛入门经典 增广路求网路最大流
* */
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
public class LargestFlow {
static final int MAXN = 100;
static int[][] cap = new int[MAXN][MAXN];// 边上最大容量
static int[][] flow = new int[MAXN][MAXN];// 边上实际流量
static int[] p = new int[MAXN];// 增广路上的父节点
static int[] a = new int[MAXN];// 每个节点路径上的最小残量 a[t]就是整条路径上的最小残量
static int n;// 顶点数
static int m;// 边数
static int s, t;// 起点和终点
static LinkedList<Integer> q = new LinkedList<Integer>();
static int f;// 从起点流出的最大流量值
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while ((n = scanner.nextInt()) > 0) {
m = scanner.nextInt();
s = scanner.nextInt();
t = scanner.nextInt();
for (int i = 1; i <= m; i++) {
int u = scanner.nextInt();
int v = scanner.nextInt();
cap[u][v] = scanner.nextInt();
}
for (int i = 0; i <= n; i++) {
Arrays.fill(flow[i], 0);
}
f = 0;
for (;;) {
Arrays.fill(a, 0);
a[s] = Integer.MAX_VALUE;
q.offer(s);
while (q.size() > 0) {// 使用BFS找增光路径
int u = q.poll();
for (int v = 1; v <= n; v++) {
if (a[v] == 0 && cap[u][v] > flow[u][v]) {// 找到新节点
p[v] = u;// 记录父节点
q.offer(v);// 入队列
a[v] = Math.min(a[u], cap[u][v] - flow[u][v]);// 更新最小残量
}
}
}
if (a[t] == 0)
break;// 不存在增广路 当前流已经是最大流
for (int u = t; u != s; u = p[u]) {// 从汇点逆向更新流量值
flow[p[u]][u] += a[t];// 更新正向流量
flow[u][p[u]] -= a[t];// 更新逆向流量
}
f += a[t];
}
System.out.println(f);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (cap[i][j] > 0 && flow[i][j] > 0) {
System.out.printf("%d %d %d/%d\n", i, j, flow[i][j],
cap[i][j]);
}
}
}
}
}
}