#include <bits/stdc++.h>
using namespace std;
int N;
int con[500][500], vst[500];
int a[500], b[500], dem[500];
int adj[500][500], deg[500];
int cur[500], tmp[500];
int id[500], cnt;
int pre[500], path[500], np;
int src[500 * 500 * 2], tar[500 * 500 * 2], sz[500 * 500 * 2], K;
queue<int> q;
bool cmp(int u, int v) { return dem[u] < dem[v]; }
void move(int s, int t, int m) {
  int i, u, v;
  if (m == 0) return;
  for (i = 0; i < cnt; i++) pre[id[i]] = -1;
  q.push(s);
  pre[s] = -2;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (i = 0; i < deg[u]; i++) {
      v = adj[u][i];
      if (pre[v] != -1) continue;
      pre[v] = u;
      q.push(v);
    }
  }
  np = 0;
  for (u = t; u != s; u = pre[u]) path[np++] = u;
  path[np++] = s;
  reverse(path, path + np);
  for (i = 0; i < np; i++) tmp[path[i]] = cur[path[i]];
  for (i = 0; i < np - 2; i++) {
    u = path[i];
    v = path[i + 1];
    if (tmp[v] >= m) continue;
    src[K] = u;
    tar[K] = v;
    sz[K] = m - tmp[v];
    K++;
    tmp[u] -= m - tmp[v];
    tmp[v] = m;
  }
  src[K] = path[np - 2];
  tar[K] = path[np - 1];
  sz[K] = m;
  K++;
  tmp[path[np - 2]] -= m;
  for (i = np - 1; i; i--) {
    u = path[i - 1];
    v = path[i];
    if (cur[v] == tmp[v]) continue;
    src[K] = u;
    tar[K] = v;
    sz[K] = cur[v] - tmp[v];
    K++;
    tmp[u] -= cur[v] - tmp[v];
  }
  cur[s] -= m;
  cur[t] += m;
  dem[s] += m;
  dem[t] -= m;
}
bool Solve() {
  int u, v, i, j, k;
  long long A, B;
  for (u = 0; u < N; u++) {
    deg[u] = 0;
    for (v = 0; v < N; v++)
      if (con[u][v]) adj[u][deg[u]++] = v;
  }
  K = 0;
  memset(vst, 0, sizeof(vst));
  for (i = 0; i < N; i++) {
    cur[i] = a[i];
    dem[i] = b[i] - a[i];
  }
  for (i = 0; i < N; i++) {
    if (vst[i]) continue;
    q.push(i);
    vst[i] = 1;
    cnt = 0;
    while (!q.empty()) {
      u = q.front();
      q.pop();
      id[cnt++] = u;
      for (j = 0; j < deg[u]; j++) {
        v = adj[u][j];
        if (vst[v]) continue;
        vst[v] = 1;
        q.push(v);
      }
    }
    A = B = 0;
    for (j = 0; j < cnt; j++) {
      u = id[j];
      A += a[u];
      B += b[u];
    }
    if (A != B) return false;
    sort(id, id + cnt, cmp);
    j = 0;
    k = cnt - 1;
    while (j < k) {
      if (dem[id[j]] + dem[id[k]] == 0) {
        move(id[j], id[k], dem[id[k]]);
        j++;
        k--;
      } else if (dem[id[j]] + dem[id[k]] < 0) {
        move(id[j], id[k], dem[id[k]]);
        k--;
      } else {
        move(id[j], id[k], -dem[id[j]]);
        j++;
      }
    }
  }
  return true;
}
int main() {
  int V, M, i, u, v;
  scanf("%d%d%d", &N, &V, &M);
  for (i = 0; i < N; i++) scanf("%d", &a[i]);
  for (i = 0; i < N; i++) scanf("%d", &b[i]);
  memset(con, 0, sizeof(con));
  for (i = 0; i < M; i++) {
    scanf("%d%d", &u, &v);
    u--, v--;
    con[u][v] = con[v][u] = 1;
  }
  if (Solve()) {
    printf("%d\n", K);
    for (i = 0; i < K; i++) printf("%d %d %d\n", src[i] + 1, tar[i] + 1, sz[i]);
  } else
    puts("NO");
  return 0;
}
