#include <bits/stdc++.h>
using namespace std;
const int nn = 600;
int f[nn], a[nn], b[nn], v[nn], sum[nn], d[nn];
long long sa[nn], sb[nn];
int N, V, _E, opts, delta;
vector<int> E[nn], e[nn];
struct pp {
  int x, y, z;
} opt[nn * nn * 2];
int find(int x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
void dfs(int x) {
  v[x] = 1;
  for (int i = 0; i < E[x].size(); ++i) {
    int j = E[x][i];
    if (v[j]) continue;
    if (delta <= 0) return;
    e[x].push_back(j);
    if (a[j] < b[j]) {
      sum[j] = b[j] - a[j];
      if (sum[j] > delta) sum[j] = delta;
      d[j] = sum[j];
      delta -= sum[j];
    }
    dfs(j);
    sum[x] += sum[j];
  }
}
void add(int x, int y, int z) {
  if (!z) return;
  opts++;
  opt[opts].x = x;
  opt[opts].y = y;
  opt[opts].z = z;
  a[x] -= z;
  a[y] += z;
}
int trans(int x, int y) {
  if (d[x] > 0) y -= d[x];
  for (int i = 0; i < e[x].size(); ++i) {
    int j = e[x][i];
    if (sum[j] > 0) {
      if (a[j] >= sum[j]) {
        trans(j, sum[j]);
        add(x, j, sum[j]);
      } else {
        int res = a[j];
        add(x, j, sum[j] - a[j]);
        trans(j, sum[j]);
        add(x, j, res);
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &N, &V, &_E);
  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) f[i] = i;
  for (int _ = 1; _ <= _E; ++_) {
    int x, y;
    scanf("%d%d", &x, &y);
    E[x].push_back(y);
    E[y].push_back(x);
    f[find(x)] = find(y);
  }
  for (int i = 1; i <= N; ++i)
    f[i] = find(f[i]), sa[f[i]] += a[i], sb[f[i]] += b[i];
  for (int i = 1; i <= N; ++i) {
    if (sa[i] != sb[i]) {
      puts("NO");
      return 0;
    }
  }
  for (int i = 1; i <= N; ++i) {
    if (a[i] <= b[i]) continue;
    for (int j = 1; j <= N; ++j) v[j] = 0, sum[j] = 0, d[j] = 0, e[j].clear();
    delta = a[i] - b[i];
    dfs(i);
    trans(i, a[i] - b[i]);
  }
  cout << opts << endl;
  for (int i = 1; i <= opts; ++i)
    cout << opt[i].x << ' ' << opt[i].y << ' ' << opt[i].z << endl;
  return 0;
}
