#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;
struct Edge {
  int num, next;
  bool avai;
} e[MAXN * 5];
int en = 0, start[MAXN];
int d[MAXN];
inline void Add_edge(int p, int q) {
  en++;
  e[en].num = q;
  e[en].next = start[p];
  start[p] = en;
  d[p]++;
  e[en].avai = true;
  en++;
  e[en].num = p;
  e[en].next = start[q];
  start[q] = en;
  d[q]++;
  e[en].avai = true;
}
int fa[MAXN];
int getfa(int p) {
  if (p == fa[p]) return p;
  return fa[p] = getfa(fa[p]);
}
long long s[MAXN];
int n, v;
int a[MAXN], b[MAXN];
int ans[1000000][3], top = 0;
bool u[MAXN];
int best[MAXN];
int po, amo;
void dfs1(int p) {
  u[p] = true;
  for (int i = start[p]; i != 0; i = e[i].next)
    if (e[i].avai && !u[e[i].num]) {
      best[e[i].num] = min(v - a[p], best[p]);
      fa[e[i].num] = p;
      if (min(a[e[i].num], best[e[i].num]) > amo) {
        amo = min(a[e[i].num], best[e[i].num]);
        po = e[i].num;
      }
      dfs1(e[i].num);
    }
}
void dfs2(int p) {
  u[p] = true;
  for (int i = start[p]; i != 0; i = e[i].next)
    if (e[i].avai && !u[e[i].num]) {
      best[e[i].num] = min(a[p], best[p]);
      fa[e[i].num] = p;
      if (min(v - a[e[i].num], best[e[i].num]) > amo) {
        amo = min(v - a[e[i].num], best[e[i].num]);
        po = e[i].num;
      }
      dfs2(e[i].num);
    }
}
void work(int p) {
  if (a[p] == b[p]) return;
  for (int t = 1;; t++) {
    if (a[p] == b[p]) return;
    memset(u, 0, sizeof(u));
    memset(best, 60, sizeof(best));
    memset(fa, 0, sizeof(fa));
    amo = 0;
    if (a[p] < b[p]) {
      dfs1(p);
      if (amo > b[p] - a[p]) amo = b[p] - a[p];
      while (po != p) {
        top++;
        ans[top][0] = po;
        ans[top][1] = fa[po];
        ans[top][2] = amo;
        a[po] -= amo;
        a[fa[po]] += amo;
        po = fa[po];
      }
    } else {
      dfs2(p);
      if (amo > a[p] - b[p]) amo = a[p] - b[p];
      while (po != p) {
        top++;
        ans[top][1] = po;
        ans[top][0] = fa[po];
        ans[top][2] = amo;
        a[po] += amo;
        a[fa[po]] -= amo;
        po = fa[po];
      }
    }
  }
}
int main() {
  int t;
  scanf("%d%d%d", &n, &v, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) fa[i] = i;
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (getfa(x) != getfa(y)) {
      Add_edge(x, y);
      fa[getfa(x)] = getfa(y);
    }
  }
  for (int i = 1; i <= n; i++) s[getfa(i)] += a[i] - b[i];
  for (int i = 1; i <= n; i++)
    if (s[i] != 0) {
      printf("NO\n");
      return 0;
    }
  bool f = true;
  while (f) {
    f = false;
    for (int i = 1; i <= n; i++)
      if (d[i] == 1) {
        work(i);
        for (int j = start[i]; j != 0; j = e[j].next)
          if (e[j].avai) {
            int nm = ((j - 1) ^ 1) + 1;
            e[nm].avai = false;
            e[j].avai = false;
            d[i]--;
            d[e[j].num]--;
            break;
          }
        f = true;
        break;
      }
  }
  printf("%d\n", top);
  for (int i = 1; i <= top; i++)
    printf("%d %d %d\n", ans[i][0], ans[i][1], ans[i][2]);
  return 0;
}
