#include <bits/stdc++.h>
const int n = 305;
int N, E, V, e, i, Ans, x, y, f1, f2;
int son[n], A[n], B[n], f[n], ed[2 * n], next[2 * n];
int S[2 * n * n], T[2 * n * n], W[2 * n * n];
long long p[n], C[n];
void read(int &x) {
  char ch;
  x = 0;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar())
    ;
}
void Addedge(int i, int j) { ed[++e] = j, next[e] = son[i], son[i] = e; }
int getfather(int i) {
  if (f[i] == i) return i;
  f[i] = getfather(f[i]);
  return f[i];
}
void Get(int i, int last) {
  int j;
  p[i] = (long long)A[i] - B[i];
  for (j = son[i]; j; j = next[j])
    if (ed[j] != last) {
      Get(ed[j], i);
      p[i] += p[ed[j]];
    }
}
void dfs(int i, int last, int P) {
  int j, tmp, Tmp;
  for (j = son[i]; j; j = next[j])
    if (ed[j] != last && p[ed[j]] > 0) {
      if (p[ed[j]] < P)
        tmp = p[ed[j]];
      else
        tmp = P;
      A[i] += tmp, P -= tmp;
      if (A[ed[j]] > B[ed[j]]) {
        if (A[ed[j]] >= tmp) {
          S[++Ans] = ed[j], T[Ans] = i, W[Ans] = tmp;
          A[ed[j]] -= tmp;
          if (A[ed[j]] < B[ed[j]]) dfs(ed[j], i, B[ed[j]] - A[ed[j]]);
        } else {
          S[++Ans] = ed[j], T[Ans] = i, W[Ans] = A[ed[j]];
          tmp -= A[ed[j]], A[ed[j]] = 0;
          dfs(ed[j], i, B[ed[j]] + tmp);
          S[++Ans] = ed[j], T[Ans] = i, W[Ans] = tmp;
          A[ed[j]] -= tmp;
        }
      } else {
        if (A[ed[j]] >= tmp) {
          S[++Ans] = ed[j], T[Ans] = i, W[Ans] = tmp;
          A[ed[j]] -= tmp;
          dfs(ed[j], i, tmp);
        } else {
          S[++Ans] = ed[j], T[Ans] = i, W[Ans] = A[ed[j]];
          Tmp = tmp - A[ed[j]], A[ed[j]] = 0;
          dfs(ed[j], i, tmp);
          S[++Ans] = ed[j], T[Ans] = i, W[Ans] = Tmp;
          A[ed[j]] -= Tmp;
        }
      }
    }
}
int main() {
  read(N), read(V), read(E);
  for (i = 1; i <= N; ++i) read(A[i]);
  for (i = 1; i <= N; ++i) read(B[i]);
  for (i = 1; i <= N; ++i) f[i] = i;
  for (i = 1; i <= E; ++i) {
    read(x), read(y);
    f1 = getfather(x), f2 = getfather(y);
    if (f1 != f2) {
      Addedge(x, y), Addedge(y, x);
      f[f1] = f2;
    }
  }
  for (i = 1; i <= N; ++i) f[i] = getfather(i);
  for (i = 1; i <= N; ++i) {
    C[f[i]] += (long long)A[i];
    C[f[i]] -= (long long)B[i];
  }
  for (i = 1; i <= N; ++i)
    if (C[i] != 0) {
      printf("NO\n");
      return 0;
    }
  for (i = 1; i <= N; ++i)
    if (A[i] < B[i]) {
      Get(i, 0);
      dfs(i, 0, B[i] - A[i]);
    }
  printf("%d\n", Ans);
  for (i = 1; i <= Ans; ++i) printf("%d %d %d\n", S[i], T[i], W[i]);
  return 0;
}
