#include <bits/stdc++.h>
int a[300], b[300];
int nd[2 * 50000], nxt[2 * 50000], ut[300], dr;
int r, rx[2 * 300 * 300], ry[2 * 300 * 300], rc[2 * 300 * 300];
int c[300], dc, ca[300], da, cb[300], db;
char fol[300], fol2[300];
int v;
void comp(int x) {
  fol[x] = 1;
  c[dc++] = x;
  int p = ut[x];
  while (p != -1) {
    if (!fol[nd[p]]) comp(nd[p]);
    p = nxt[p];
  }
}
inline int min2(int x, int y) { return x < y ? x : y; }
inline char impart() {
  int i;
  long long d = 0;
  da = db = 0;
  for (i = 0; i < dc; i++) {
    if (a[c[i]] > b[c[i]]) {
      ca[da++] = c[i];
    }
    if (a[c[i]] < b[c[i]]) {
      cb[db++] = c[i];
    }
    d += a[c[i]] - b[c[i]];
  }
  if (d == 0) return 1;
  return 0;
}
inline void add(int x, int y) {
  nd[dr] = y;
  nxt[dr] = ut[x];
  ut[x] = dr;
  dr++;
}
char mve(int x, int y, int d) {
  if (x == y) return 1;
  fol2[x] = 1;
  int p = ut[x], aux;
  char g = 0;
  while (p != -1 && !g) {
    if (!fol2[nd[p]]) {
      rx[r] = x;
      ry[r] = nd[p];
      aux = min2(d, v - a[nd[p]]);
      rc[r] = aux;
      a[x] -= rc[r];
      a[nd[p]] += rc[r];
      r++;
      g = mve(nd[p], y, d);
      if (!g) {
        r--;
        a[nd[p]] -= rc[r];
        a[x] += rc[r];
      } else {
        if (aux < d) {
          rx[r] = x;
          ry[r] = nd[p];
          rc[r] = d - aux;
          a[x] -= rc[r];
          a[nd[p]] += rc[r];
          r++;
        }
      }
    }
    p = nxt[p];
  }
  fol2[x] = 0;
  return g;
}
int main() {
  int n, e, i, x, y, d, ma, mb;
  scanf("%d%d%d", &n, &v, &e);
  memset(ut, -1, sizeof ut);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n; i++) scanf("%d", &b[i]);
  for (i = 0; i < e; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    add(x, y);
    add(y, x);
  }
  for (i = 0; i < n; i++) {
    dc = 0;
    if (!fol[i]) {
      comp(i);
      if (!impart()) {
        printf("NO\n");
        return 0;
      } else {
        while (da > 0) {
          ma = a[ca[da - 1]] - b[ca[da - 1]];
          mb = b[cb[db - 1]] - a[cb[db - 1]];
          if (ma < mb) {
            mve(ca[da - 1], cb[db - 1], ma);
            da--;
          } else {
            mve(ca[da - 1], cb[db - 1], mb);
            db--;
            if (ma == mb) da--;
          }
        }
      }
    }
  }
  printf("%d\n", r);
  for (i = 0; i < r; i++) {
    printf("%d %d %d\n", rx[i] + 1, ry[i] + 1, rc[i]);
  }
  return 0;
}
