#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000,1000000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
struct output {
  long long from, to, val;
};
long long n, V, e, tot = 0;
long long a[305], b[305];
long long d[305][305], vis[305], used[305], h[305];
output ans[305 * 305 * 4];
long long size = 0;
long long q[305], sz = 0;
void add(long long from, long long to, long long val) {
  output now = {from + 1, to + 1, val};
  ans[size++] = now;
}
void dfs(long long v) {
  vis[v] = 1;
  tot += a[v] - b[v];
  for (long long(i) = 0; (i) < (long long)(n); (i)++)
    if (!vis[i] && d[v][i]) dfs(i), d[v][i] = d[i][v] = 2;
  q[sz++] = v;
}
void push(long long v, long long val) {
  h[v] = 1;
  for (long long(i) = 0; (i) < (long long)(n); (i)++) {
    if (!val) break;
    if (!h[i] && !used[i] && d[v][i] == 2) {
      if (V - a[i] >= val) {
        add(v, i, val);
        a[i] += val;
        a[v] -= val;
        val = 0;
      } else {
        push(i, val - (V - a[i]));
        long long now = min(val, V - a[i]);
        add(v, i, now);
        a[i] += now;
        a[v] -= now;
        val -= now;
      }
    }
  }
}
void pull(long long v, long long val) {
  h[v] = 1;
  for (long long(i) = 0; (i) < (long long)(n); (i)++) {
    if (!val) break;
    if (!h[i] && !used[i] && d[v][i] == 2) {
      if (a[i] >= val) {
        add(i, v, val);
        a[i] -= val;
        a[v] += val;
        val = 0;
      } else {
        pull(i, val - a[i]);
        long long now = min(val, a[i]);
        add(i, v, now);
        a[v] += now;
        a[i] -= now;
        val -= now;
      }
    }
  }
}
int main(void) {
  cin >> n >> V >> e;
  for (long long(i) = 0; (i) < (long long)(n); (i)++) scanf("%I64d", &a[i]);
  for (long long(i) = 0; (i) < (long long)(n); (i)++) scanf("%I64d", &b[i]);
  for (long long(i) = 0; (i) < (long long)(e); (i)++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    d[x][y] = d[y][x] = 1;
  }
  for (long long(i) = 0; (i) < (long long)(n); (i)++)
    if (!vis[i]) {
      tot = sz = 0;
      dfs(i);
      if (tot) cout << "NO" << endl, exit(0);
      for (long long(j) = 0; (j) < (long long)(sz); (j)++) {
        long long now = q[j];
        memset(h, 0, sizeof(h));
        if (a[now] > b[now]) push(now, a[now] - b[now]);
        if (a[now] < b[now]) pull(now, b[now] - a[now]);
        used[now] = 1;
      }
    }
  printf("%d\n", int(size));
  for (long long(i) = 0; (i) < (long long)(size); (i)++) {
    printf("%d %d %d\n", (int)ans[i].from, (int)ans[i].to, (int)ans[i].val);
  }
  return 0;
}
