Problem: A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tubes equals e. Volume of each vessel equals v liters. Of course, the amount of the water in any vessel cannot exceed v liters in the process of transfusions.

Given the initial amounts ai of water in the vessels and the desired amounts bi find a sequence of transfusions that deals with the task. Total number of transfusions must not exceed 2·n2.

Input

First line of the input contains integers n, v, e (1 ≤ n ≤ 300, 1 ≤ v ≤ 109, 0 ≤ e ≤ 50000).

Next two lines contain n integers each: initial ai and the desired amounts bi of water in corresponding vessels (0 ≤ ai, bi ≤ v).

Next e lines describe one tube each in the format x y (1 ≤ x, y ≤ n, x ≠ y) for a tube between vessels number x and y. There might be multiple tubes between two vessels. You may assume that vessels are numbered from 1 to n in some way.

Output

Print "NO" (without quotes), if such sequence of transfusions does not exist.

Otherwise print any suitable sequence in the following format. On the first line print the total number of transfusions k (k should not exceed 2·n2). In the following k lines print transfusions in the format x y d (transfusion of d liters from the vessel number x to the vessel number y, x and y must be distinct). For all transfusions d must be a non-negative integer.

Examples

Input

2 10 1
1 9
5 5
1 2


Output

1
2 1 4


Input

2 10 0
5 2
4 2


Output

NO


Input

2 10 0
4 2
4 2


Output

0

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {
	
	class State {
		int from, to, cnt;
		
		public State(int from, int to, int cnt) {
			this.from = from;
			this.to = to;
			this.cnt = cnt;
		}
	}
	
	int n, value, m;
	boolean g [][];
	ArrayList<State> answer = new ArrayList<>();
	int [] cur, need, deg;
	boolean [] used, u, isCutpoint;
	int [] tin, fup;
	int timer = 0;
	
	void dfs (int v, int pre) {
		used[v] = true;
		tin[v] = fup[v] = timer++;
		int children = 0;
		for (int to = 0; to < n; to++) {
			if (g[v][to]) {
				if (to == pre) continue;
				if (used[to]) {
					fup[v] = min (fup[v], tin[to]);
				} else {
					children++;
					dfs (to, v);
					fup[v] = min (fup[v], fup[to]);
					if (fup[to] >= tin[v] && pre != -1)
						isCutpoint[v] = true;
				}
			}
		}
		if (pre == -1 && children > 1)
			isCutpoint[v] = true;
	}
	
	boolean proccess (int start) {
		if (cur[start] == need[start]) return true;
		int diff = need[start] - cur[start];
		Queue<Integer> q = new ArrayDeque<>();
		int d [] = new int [n];
		Arrays.fill(d, Integer.MAX_VALUE / 2);
		d[start] = 0;
		q.add(start);
		ArrayList<Integer> list = new ArrayList<>();
		while (!q.isEmpty()) {
			int v = q.poll();
			list.add(v);
			for (int to = 0; to < n; to++) {
				if (g[v][to]) {
					if (d[to] > d[v] + 1) {
						d[to] = d[v] + 1;
						q.add(to);
					}
				}
			}
		}
		if (diff > 0) {
			for (int j = list.size() - 1; j >= 1; j--) {
				int v = list.get(j);
				if (d[v] == 1) continue;
				int bestk = -1;
				for (int k = 0; k < n; k++) {
					if (g[v][k] && d[k] == d[v] - 1) {
						int canMove = min (cur[v], value - cur[k]);
						if (canMove > 0) {
							cur[k] += canMove;
							cur[v] -= canMove;
							answer.add(new State(v + 1, k + 1, canMove));
						}
					}
				}
			}
			for (int to = 0; to < n; to++) {
				if (g[start][to]) {
					int canMove = min (cur[to], value - cur[start]);
					if (cur[start] + canMove > need[start]) {
						canMove = need[start] - cur[start];
					}
					if (canMove > 0) {
						cur[start] += canMove;
						cur[to] -= canMove;
						answer.add(new State(to + 1, start + 1, canMove));
					}
				}
			}
			return cur[start] == need[start];
		} else {
			for (int j = list.size() - 1; j >= 1; j--) {
				int v = list.get(j);
				int bestk = -1;
				for (int k = 0; k < n; k++) {
					if (g[v][k] && d[k] == d[v] + 1) {
						int canMove = min (cur[v], value - cur[k]);
						if (canMove > 0) {
							cur[k] += canMove;
							cur[v] -= canMove;
							answer.add(new State(v + 1, k + 1, canMove));
						}
					}
				}
			}
			for (int to = 0; to < n; to++) {
				if (g[start][to]) {
					int canMove = min (cur[start], value - cur[to]);
					if (cur[start] - canMove < need[start]) {
						canMove = cur[start] - need[start];
					}
					if (canMove > 0) {
						cur[start] -= canMove;
						cur[to] += canMove;
						answer.add(new State(start + 1, to + 1, canMove));
					}
				}
			}
			return cur[start] == need[start];
		}
		
	}
	
	public void solve() throws Throwable {
		n = sc.nextInt();
		value = sc.nextInt();
		m = sc.nextInt();
		g = new boolean [n][n];
		cur = new int [n];
		need = new int [n];
		
		for (int i = 0; i < n; i++) {
			cur[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			need[i] = sc.nextInt();
		}
		
		for (int i = 0; i < m; i++) {
			int v1 = sc.nextInt() - 1;
			int v2 = sc.nextInt() - 1;
			g[v1][v2] = true;
			g[v2][v1] = true;
		}
		
		u = new boolean [n];
		
		for (int times = 0; times < n; times++) {
			used = new boolean [n];
			fup = new int [n];
			tin = new int [n];
			isCutpoint = new boolean [n];
			timer = 0;
			for (int i = 0; i < n; i++) {
				if (!u[i] && !used[i]) {
					dfs (i, -1);
				}
			}
			
			for (int i = 0; i < n; i++) {
				if (!u[i] && !isCutpoint[i]) {
					u[i] = true;
					if (!proccess(i)) {
						out.println("NO");
						return;
					}
					for (int to = 0; to < n; to++) {
						if (g[i][to]) {
							g[i][to] = g[to][i] = false;
						}
					}
					break;
				}
			}
		}
		
		out.println(answer.size());
		for (int i = 0; i < answer.size(); i++) {
			out.println(answer.get(i).from+" "+answer.get(i).to+" "+answer.get(i).cnt);
		}
		
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Solution.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Solution(), "", (1 << 26));
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}

	public String nextToken() throws IOException {
		while (strTok == null || !strTok.hasMoreTokens()) {
			strTok = new StringTokenizer(reader.readLine().trim());
		}
		return strTok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

}