#include <bits/stdc++.h>
using namespace std;
const int N = 310, S = 301, T = 302, M = 51000;
struct Edge {
  int y, nex;
  long long z;
} g[M * 3];
int n, v, m, dis[N], sz = 1, pos[N], az, ax[M], ay[M], aw[M], que[N], hd, tl,
                     w[N], a[N], b[N], in[N];
long long sum, p1, p2;
void Init(int x, int y, long long z) {
  g[++sz].y = y;
  g[sz].nex = pos[x];
  g[sz].z = z;
  pos[x] = sz;
}
bool Bfs() {
  memset(dis, 0, sizeof(dis));
  que[hd = tl = 1] = S, dis[S] = 1;
  while (hd <= tl) {
    int x = que[hd++];
    for (int i = pos[x]; i; i = g[i].nex)
      if (g[i].z) {
        int y = g[i].y;
        if (!dis[y]) dis[y] = dis[x] + 1, que[++tl] = y;
      }
  }
  return dis[T];
}
long long Dfs(int x, long long mx) {
  if (x == T) return mx;
  long long ret = 0;
  for (int i = pos[x]; i; i = g[i].nex) {
    int y = g[i].y;
    long long k;
    if (mx && g[i].z && dis[y] == dis[x] + 1 && (k = Dfs(y, min(g[i].z, mx)))) {
      g[i].z -= k, g[i ^ 1].z += k, mx -= k, ret += k;
    }
  }
  if (mx) dis[x] = 0;
  return ret;
}
void Dinic() {
  long long ret = 0;
  while (Bfs()) {
    while (ret = Dfs(S, (1000000000000000LL))) sum += ret;
  }
}
bool Print() {
  for (int i = 1; i <= n; i++) in[i] = 0;
  for (int x = 1; x <= n; x++) {
    for (int i = pos[x]; i; i = g[i].nex)
      if (g[i].z < (1000000000000000LL)) in[g[i].y]++;
  }
  hd = 1, tl = 0;
  for (int i = 1; i <= n; i++)
    if (!in[i]) que[++tl] = i;
  if (tl == n) return 0;
  while (hd <= tl) {
    int x = que[hd++];
    for (int i = pos[x]; i; i = g[i].nex)
      if (g[i].y != T && g[i].y != S) {
        int y = g[i].y;
        long long z = min(((1000000000000000LL) - g[i].z),
                          (long long)min(v - w[y], w[x]));
        if (z > 0) {
          ax[++az] = x, ay[az] = y, aw[az] = z;
          w[y] += z, w[x] -= z, g[i].z += z;
        }
        in[y]--;
        if (!in[y]) que[++tl] = y;
      }
  }
  return 1;
}
int main() {
  scanf("%d%d%d", &n, &v, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), w[i] = a[i];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (a[i] > b[i])
      Init(S, i, a[i] - b[i]), Init(i, S, 0), p1 += a[i] - b[i];
    else
      Init(i, T, b[i] - a[i]), Init(T, i, 0), p2 += b[i] - a[i];
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    Init(x, y, (1000000000000000LL)), Init(y, x, (1000000000000000LL));
  }
  Dinic();
  if (p1 != p2 || sum != p1) {
    puts("NO");
    return 0;
  }
  while (Print())
    ;
  printf("%d\n", az);
  for (int i = 1; i <= az; i++) printf("%d %d %d\n", ax[i], ay[i], aw[i]);
  return 0;
}
