#include <bits/stdc++.h>
using namespace std;
int n, m;
int maxvol;
int d[300][300];
int nxt[300][300];
int have[300], want[300];
int nans;
int ans[180000][3];
int ndelay;
int delay[300][3];
void input() {
  scanf("%d%d%d", &n, &maxvol, &m);
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) {
      d[i][j] = i == j ? 0 : INT_MAX;
      nxt[i][j] = -1;
    }
  for (int i = (0); i < (n); ++i) scanf("%d", &have[i]);
  for (int i = (0); i < (n); ++i) scanf("%d", &want[i]);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    d[a][b] = d[b][a] = 1;
    nxt[a][b] = b;
    nxt[b][a] = a;
  }
}
bool solve() {
  for (int k = (0); k < (n); ++k)
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (n); ++j)
        if (d[i][k] != INT_MAX && d[k][j] != INT_MAX &&
            d[i][k] + d[k][j] < d[i][j]) {
          d[i][j] = d[i][k] + d[k][j];
          nxt[i][j] = nxt[i][k];
        }
  nans = 0;
  while (true) {
    int from = -1;
    for (int i = (0); i < (n); ++i)
      if (have[i] > want[i]) {
        from = i;
        break;
      }
    if (from == -1) break;
    int to = -1;
    for (int i = (0); i < (n); ++i)
      if (have[i] < want[i] && d[from][i] != INT_MAX &&
          (to == -1 || d[from][i] < d[from][to]))
        to = i;
    if (to == -1) break;
    int amount = min(have[from] - want[from], want[to] - have[to]);
    ndelay = 0;
    for (int prev = from, at = nxt[from][to]; at != -1;
         prev = at, at = nxt[at][to]) {
      int now = min(amount, maxvol - have[at]);
      if (now > 0) {
        have[prev] -= now;
        have[at] += now;
        assert(nans < 180000);
        ans[nans][0] = prev;
        ans[nans][1] = at;
        ans[nans][2] = now;
        ++nans;
      }
      if (amount > now) {
        have[prev] -= (amount - now);
        have[at] += (amount - now);
        assert(ndelay < 300);
        delay[ndelay][0] = prev;
        delay[ndelay][1] = at;
        delay[ndelay][2] = amount - now;
        ++ndelay;
      }
    }
    for (int i = ndelay - 1; i >= 0; --i) {
      assert(nans < 180000);
      ans[nans][0] = delay[i][0];
      ans[nans][1] = delay[i][1];
      ans[nans][2] = delay[i][2];
      ++nans;
    }
  }
  for (int i = (0); i < (n); ++i)
    if (have[i] != want[i]) return false;
  return true;
}
void output(bool solved) {
  if (!solved) {
    printf("NO\n");
    return;
  }
  printf("%d\n", nans);
  for (int i = (0); i < (nans); ++i)
    printf("%d %d %d\n", ans[i][0] + 1, ans[i][1] + 1, ans[i][2]);
}
void run(int casenr) {
  input();
  bool ret = solve();
  output(ret);
}
int oldhave[300];
void test() {
  int seed = 1371310971;
  srand(seed);
  n = 100;
  m = 1000;
  maxvol = 1000;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) {
      d[i][j] = i == j ? 0 : INT_MAX;
      nxt[i][j] = -1;
    }
  for (int i = (0); i < (m); ++i) {
    int a = rand() % n, b = rand() % n;
    if (a == b) continue;
    d[a][b] = d[b][a] = 1;
    nxt[a][b] = b;
    nxt[b][a] = a;
  }
  int sum = maxvol * n * 9 / 10;
  {
    int left = sum;
    for (int i = (0); i < (n); ++i) {
      int maxrem = (n - i - 1) * maxvol;
      int minnow = left > maxrem ? left - maxrem : 0;
      int x = min(maxvol - minnow - 50, left);
      have[i] = x <= 0 ? minnow : minnow + rand() % x;
      left -= have[i];
    }
  }
  {
    int left = sum;
    for (int i = (0); i < (n); ++i) {
      int maxrem = (n - i - 1) * maxvol;
      int minnow = left > maxrem ? left - maxrem : 0;
      int x = min(maxvol - minnow - 50, left);
      want[i] = x <= 0 ? minnow : minnow + rand() % x;
      left -= want[i];
    }
  }
  for (int i = (0); i < (n); ++i) oldhave[i] = have[i];
  if (!solve()) {
    printf("not solved\n");
    return;
  }
  for (int i = (0); i < (n); ++i) have[i] = oldhave[i];
  for (int i = (0); i < (nans); ++i) {
    int a = ans[i][0], b = ans[i][1], c = ans[i][2];
    assert(d[a][b] == 1);
    assert(have[a] >= c);
    have[a] -= c;
    have[b] += c;
    assert(have[b] <= maxvol);
  }
  for (int i = (0); i < (n); ++i) assert(have[i] == want[i]);
}
int main() {
  run(1);
  return 0;
}
