#include <bits/stdc++.h>
using namespace std;
int n, V, m, a[333], b[333];
long long sa, sb;
vector<int> e[333], g[333];
vector<pair<pair<int, int>, int> > res;
bool used[333], killed[333];
vector<int> order;
int pr[333];
int q[333], level[333], head, tail;
void dfs(int u) {
  used[u] = true;
  sa += a[u];
  sb += b[u];
  for (__typeof(e[u].begin()) it = e[u].begin(); it != e[u].end(); ++it) {
    int v = *it;
    if (!used[v]) {
      g[u].push_back(v);
      g[v].push_back(u);
      dfs(v);
    }
  }
  order.push_back(u);
}
void go(int u, int v, int x) {
  assert(x >= 0);
  if (x == 0) return;
  a[v] += x;
  a[u] -= x;
  res.push_back(make_pair(make_pair(u, v), x));
}
void doIt() {
  for (__typeof(order.begin()) it = order.begin(); it != order.end(); ++it) {
    int second = *it;
    memset(level, -1, sizeof(level));
    head = tail = 0;
    level[second] = 0;
    q[tail++] = second;
    while (head < tail) {
      int u = q[head++];
      for (__typeof(g[u].begin()) it = g[u].begin(); it != g[u].end(); ++it) {
        int v = *it;
        if (level[v] == -1 && !killed[v]) {
          level[v] = level[u] + 1;
          q[tail++] = v;
        }
      }
    }
    int need = b[second] - a[second];
    killed[second] = true;
    if (need == 0) continue;
    for (int i = tail - 1; i > 0; --i) {
      int u = q[i];
      for (__typeof(g[u].begin()) it = g[u].begin(); it != g[u].end(); ++it) {
        int v = *it;
        if (level[v] != level[u] - 1) continue;
        if (need > 0) {
          int x = min(a[u], V - a[v]);
          if (v == second) x = min(a[u], b[v] - a[v]);
          go(u, v, x);
        } else {
          int x = min(a[v], V - a[u]);
          if (v == second) x = min(a[v] - b[v], V - a[u]);
          go(v, u, x);
        }
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &V, &m);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      order.clear();
      sa = sb = 0;
      dfs(i);
      if (sa != sb) {
        puts("NO");
        return 0;
      }
      doIt();
    }
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); ++i)
    printf("%d %d %d\n", res[i].first.first + 1, res[i].first.second + 1,
           res[i].second);
  return 0;
}
