#include <bits/stdc++.h>
using namespace std;
const int N = 305;
vector<int> E[N];
pair<pair<int, int>, int> ret[N * N * 2];
pair<int, int> p[N];
int A[N], B[N], f[N], k, done[N];
void up(int u, int v, int c) {
  ret[k++] = make_pair(make_pair(u, v), c);
  A[u] -= c;
  A[v] += c;
}
void dfs(int x, int need) {
  f[x] = 1;
  for (int i = E[x].size() - 1; i >= 0 && A[x] < need; i--) {
    int j = E[x][i];
    if (f[j]) continue;
    if (done[j]) {
      int tmp = min(B[j], need - A[x]);
      up(j, x, tmp);
      dfs(j, B[j]);
      if (A[j] < B[j]) {
        up(x, j, B[j] - A[j]);
      }
    } else {
      dfs(j, need);
      int lim = min(A[j], need - A[x]);
      up(j, x, lim);
    }
  }
}
int main() {
  int n, v, m, i;
  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++) p[i - 1] = make_pair(-B[i], i);
  sort(p, p + n);
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    E[a].push_back(b);
    E[b].push_back(a);
  }
  for (int h = 0; h < n; h++) {
    i = p[h].second;
    memset(f, 0, sizeof(f));
    dfs(i, B[i]);
    done[i] = 1;
  }
  for (i = 1; i <= n; i++)
    if (A[i] != B[i]) {
      puts("NO");
      return 0;
    }
  printf("%d\n", k);
  for (i = 0; i < k; i++)
    printf("%d %d %d\n", ret[i].first.first, ret[i].first.second,
           ret[i].second);
  return 0;
}
