#include <bits/stdc++.h>
using namespace std;
const int N = 400;
bool arr[N][N];
int pre[N][N], n, e;
long long a[N], b[N], c[N], v;
int top;
struct data {
  int s, t;
  long long d;
} ans[N * N * 2];
void floyd() {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (arr[i][j]) continue;
        if (arr[i][k] && arr[k][j]) {
          arr[i][j] = true;
          pre[i][j] = k;
        }
      }
    }
  }
}
void findpath(int s, int t, int q[], int &len) {
  if (pre[s][t] == s) {
    q[len++] = t;
    return;
  } else {
    findpath(pre[s][t], t, q, len);
    findpath(s, pre[s][t], q, len);
  }
}
void dfs(int index, int q[], int len, long long d) {
  if (index + 1 == len) return;
  long long tp;
  int s = q[index], t = q[index + 1];
  if (d + a[t] > v) {
    ans[top].s = s;
    ans[top].t = t;
    tp = ans[top].d = v - a[t];
    if (tp != 0) top++;
    a[t] = v;
    a[s] -= tp;
    dfs(index + 1, q, len, d);
    ans[top].s = s;
    ans[top].t = t;
    ans[top].d = d - tp;
    if (ans[top].d != 0) top++;
    a[s] = a[s] - d + tp;
    a[t] = a[t] + d - tp;
  } else {
    ans[top].s = s;
    ans[top].t = t;
    ans[top].d = d;
    if (d != 0) top++;
    a[t] += d;
    a[s] -= d;
    dfs(index + 1, q, len, d);
  }
}
int main() {
  while (scanf("%d%I64d%d", &n, &v, &e) != EOF) {
    memset(arr, false, sizeof(arr));
    memset(pre, -1, sizeof(pre));
    long long sum = 0;
    for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
    for (int i = 1; i <= n; i++) {
      scanf("%I64d", &b[i]);
      c[i] = a[i] - b[i];
      sum += c[i];
    }
    for (int i = 0, x, y; i < e; i++) {
      scanf("%d%d", &x, &y);
      arr[x][y] = arr[y][x] = true;
      pre[x][y] = x;
      pre[y][x] = y;
    }
    if (sum != 0) {
      printf("NO\n");
      continue;
    }
    floyd();
    top = 0;
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      if (c[i] <= 0) continue;
      for (int j = 1; j <= n; j++) {
        if (c[j] >= 0 || !arr[i][j]) continue;
        long long tp = min(c[i], -c[j]);
        int path[N], len = 0;
        findpath(i, j, path, len);
        path[len++] = i;
        reverse(path, path + len);
        dfs(0, path, len, tp);
        c[i] -= tp;
        c[j] += tp;
      }
      if (c[i] > 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      printf("%d\n", top);
      for (int i = 0; i < top; i++)
        printf("%d %d %I64d\n", ans[i].s, ans[i].t, ans[i].d);
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
