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.DataInputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;

public class C {
	static class Pair implements Comparable<Pair> {
		int node, depth;

		public Pair(int n, int v) {
			node = n;
			depth = v;
		}

		public int compareTo(Pair p) {
			return new Integer(p.depth).compareTo(depth);
		}
	}

	static int[] parent;

	public static void union(int x, int y) {
		if (find(x) != find(y)) {
			parent[find(y)] = find(x);
		}
	}

	public static int find(int x) {
		if (parent[x] == x)
			return x;
		return parent[x] = find(parent[x]);
	}

	static ArrayList<Integer>[] graph;
	static PriorityQueue<Pair> pq;
	static int[] haveToPush;
	static int maxSz;
	static int[] p;
	static int[] reqVol, curVol;
	static int rem;
	public static void dfs(int cur, int parent, int depth) {
		p[cur] = parent;
		if (curVol[cur] > reqVol[cur]) {
			haveToPush[cur] = Math.min(rem,curVol[cur] - reqVol[cur]);
			rem-=haveToPush[cur];
			if(haveToPush[cur]>0)
			pq.add(new Pair(cur, depth));
		}
		for (Integer next : graph[cur]) {
			if (next != parent) {
				dfs(next, cur, depth + 1);
			}
		}
	}

	public static void relax(int idx) {
		for (Pair p : pendingList[idx]) {
			int push=Math.min(p.depth,maxSz-curVol[idx]);
			curVol[p.node] -= push;
			curVol[idx] += push;
			trans++;
			res.add((p.node + 1) + " " + (idx + 1) + " " + (push));
		}
		for (Pair p : pendingList[idx]) {
			if (pendingList[p.node].size() > 0) {
				relax(p.node);
			}
		}
	}

	static ArrayList<String> res;
	static ArrayList<Pair>[] pendingList;
	static int trans;

	public static void main(String[] args) throws Exception {
		PrintWriter out = new PrintWriter(System.out);
		Parser aa=new Parser(System.in);
		int vesCnt = aa.nextLong();
		maxSz = aa.nextLong();
		int pipeCnt = aa.nextLong();
		graph = new ArrayList[vesCnt];
		curVol = new int[vesCnt];
		reqVol = new int[vesCnt];
		long curSum = 0, reqSum = 0;
		for (int i = 0; i < vesCnt; i++) {
			curVol[i] = aa.nextLong();
			curSum += curVol[i];
		}
		for (int i = 0; i < vesCnt; i++) {
			reqVol[i] = aa.nextLong();
			reqSum += reqVol[i];
		}
		if (curSum != reqSum) {
			System.out.println("NO");
			return;
		}
		parent = new int[vesCnt];
		for (int i = 0; i < vesCnt; i++) {
			parent[i] = i;
		}
		for (int i = 0; i < vesCnt; i++) {
			graph[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < pipeCnt; i++) {
			int source = aa.nextLong() - 1;
			int dest = aa.nextLong() - 1;
			if (find(source) != find(dest)) {
				graph[source].add(dest);
				graph[dest].add(source);
				union(source, dest);
			}
		}
		p = new int[vesCnt];
		res = new ArrayList<String>();
		for (int i = 0; i < vesCnt; i++) {
			if (curVol[i] < reqVol[i]) {
//				System.out.println(i+" "+res.size());
				Arrays.fill(p, -1);
				haveToPush = new int[vesCnt];
				int[] pending = new int[vesCnt];
				pendingList = new ArrayList[vesCnt];
				for (int j = 0; j < vesCnt; j++) {
					pendingList[j] = new ArrayList<Pair>();
				}
				pq = new PriorityQueue<Pair>();
				
//				System.out.println(Arrays.toString(curVol));
//				System.out.println(Arrays.toString(reqVol));
				rem = reqVol[i] - curVol[i];
				dfs(i, -1, 0);
//				System.out.println(Arrays.toString(haveToPush));
				boolean[] vis=new boolean[vesCnt];
				while ( !pq.isEmpty()) {
					Pair pp = pq.remove();
					if(vis[pp.node]) continue;
					vis[pp.node]=true;
					int toPush = haveToPush[pp.node]
							+ pending[pp.node];
					int from = pp.node;
					int to = p[pp.node];
					if (to == -1)
						break;
//					if(i==0){
//						System.out.println(curVol[to]+" "+toPush+"  a7"+" "+to+" "+from+" "+Arrays.toString(pending)+" "+Arrays.toString(haveToPush));
//					}
					if (maxSz - curVol[to] >= toPush) {
						trans++;
						res.add((from + 1) + " " + (to + 1) + " " + toPush);
						curVol[from] -= toPush;
						curVol[to] += toPush;
						haveToPush[to] += toPush;
						if (pendingList[from].size() > 0) {
							relax(from);
						}
						if(!vis[to])
						pq.add(new Pair(to, pp.depth - 1));
					} else {
						if (curVol[to] < maxSz) {
							trans++;
							res.add((from + 1) + " " + (to + 1) + " "
									+ (maxSz - curVol[to]));
							toPush -= (maxSz - curVol[to]);
							haveToPush[to] += (maxSz - curVol[to]);
							curVol[from] -= (maxSz - curVol[to]);
							curVol[to] = maxSz;
						}
						pending[to] += (toPush);
						pendingList[to].add(new Pair(from, toPush));
						if(!vis[to])
						pq.add(new Pair(to, pp.depth - 1));
					}
				}
				if (curVol[i] != reqVol[i]) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println(trans);
		for (int i = 0; i < res.size(); i++) {
			if (i % 1000 == 0)
				out.flush();
			out.println(res.get(i));
		}
		out.flush();
	}

	static class Parser {
		final private int BUFFER_SIZE = 1 << 16;

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public char nextChar() throws Exception {
			byte c = read();
			while (c <= ' ')
				c = read();
			return (char) c;
		}

		public int nextLong() throws Exception {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
				c = read();
			} while (c > ' ');
			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws Exception {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws Exception {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}
	}
}