#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;
}
