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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, f, next;
};
struct edge e[1010];
int n, m, v, ans, num;
int head[310], a[310], b[310], d[310], fa[310], q[310], used[310], w[200010][3];
void add(int u, int v) {
  e[num].u = u;
  e[num].v = v;
  e[num].next = head[u];
  head[u] = num;
  num++;
  e[num].u = v;
  e[num].v = u;
  e[num].next = head[v];
  head[v] = num;
  num++;
}
int find(int i) { return fa[i] == i ? i : fa[i] = find(fa[i]); }
void change(int x, int y, int z) {
  if (z == 0) return;
  ans++;
  a[x] -= z;
  a[y] += z;
  w[ans][0] = x;
  w[ans][1] = y;
  w[ans][2] = z;
}
void gather(int i, int fa) {
  int j;
  j = head[i];
  while (j != -1) {
    if (e[j].f && e[j].v != fa) {
      gather(e[j].v, i);
      change(e[j].v, i, min(a[e[j].v], v - a[i]));
    }
    j = e[j].next;
  }
}
void spread(int i, int fa) {
  int j;
  j = head[i];
  while (j != -1) {
    if (e[j].f && e[j].v != fa) {
      spread(e[j].v, i);
      change(i, e[j].v, min(a[i], v - a[e[j].v]));
    }
    j = e[j].next;
  }
}
void work(int root) {
  int i, j, k, t, w;
  memset(used, 0, sizeof(used));
  memset(d, 0, sizeof(d));
  for (i = 1; i <= n; i++)
    if (find(i) == find(root)) used[i] = 1;
  for (i = 0; i < num; i += 2)
    if (used[e[i].u] && used[e[i].v]) {
      e[i].f = 1;
      e[i ^ 1].f = 1;
      d[e[i].u]++;
      d[e[i].v]++;
    }
  t = 1;
  w = 0;
  for (i = 1; i <= n; i++)
    if (used[i] && d[i] == 1) q[++w] = i;
  while (t <= w) {
    i = q[t];
    if (d[i] == 0) {
      t++;
      continue;
    }
    j = head[i];
    while (j != -1) {
      if (e[j].f) {
        k = e[j].v;
        break;
      }
      j = e[j].next;
    }
    if (b[i] > a[i]) {
      gather(k, i);
      change(k, i, b[i] - a[i]);
    } else {
      spread(k, i);
      change(i, k, a[i] - b[i]);
    }
    e[j].f = 0;
    e[j ^ 1].f = 0;
    d[k]--;
    if (d[k] == 1) q[++w] = k;
    t++;
  }
}
int main() {
  int i, j, x, y, fx, fy, flag;
  long long s1, s2;
  scanf("%d%d%d", &n, &v, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (i = 1; i <= n; i++) fa[i] = i;
  memset(head, -1, sizeof(head));
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    fx = find(x);
    fy = find(y);
    fa[fx] = fy;
    if (fx != fy) add(x, y);
  }
  flag = 1;
  for (i = 1; i <= n; i++) {
    s1 = 0;
    s2 = 0;
    for (j = 1; j <= n; j++)
      if (find(j) == find(i)) {
        s1 += a[j];
        s2 += b[j];
      }
    if (s1 != s2) {
      flag = 0;
      break;
    }
  }
  if (!flag) {
    printf("NO\n");
    return 0;
  }
  for (i = 1; i <= n; i++)
    if (a[i] != b[i]) work(i);
  printf("%d\n", ans);
  for (i = 1; i <= ans; i++) printf("%d %d %d\n", w[i][0], w[i][1], w[i][2]);
  return 0;
}