#include <bits/stdc++.h>
using namespace std;
const int N = 400;
int n, v, e;
long long sum = 0;
int a[N + 1], s[N + 1], fa[N + 1], b[N + 1];
vector<int> nei[N + 1];
int getFather(int i) {
  if (fa[i] == -1) return i;
  return fa[i] = getFather(fa[i]);
}
bool vis[N + 1];
bool mark[N + 1];
int currentVo;
vector<pair<int, pair<int, int> > > ans;
void check(int cur, int p, int &x) {
  x = abs(currentVo);
  if (currentVo < 0) currentVo = min(0, currentVo + a[cur]);
  if (currentVo > 0) currentVo = max(currentVo - (v - a[cur]), 0);
  if (currentVo) x = -1;
  return;
}
bool isg = false;
void dfs2(int cur, int p) {
  int x = 0;
  if (!currentVo) return;
  if (cur != p) check(cur, p, x);
  for (int ne : nei[cur])
    if (ne != p && !mark[ne]) dfs2(ne, cur);
  if (cur == p) return;
  if (isg) {
    if (x == -1) x = min(v - a[cur], a[p]);
    a[cur] += x;
    a[p] -= x;
    ans.push_back(make_pair(x, make_pair(p, cur)));
  } else {
    if (x == -1) x = min(v - a[p], a[cur]);
    a[cur] -= x;
    a[p] += x;
    ans.push_back(make_pair(x, make_pair(cur, p)));
  }
  return;
}
void dfs(int cur, int p) {
  sum += s[cur];
  vis[cur] = true;
  for (int ne : nei[cur])
    if (ne != p) dfs(ne, cur);
  mark[cur] = true;
  currentVo = a[cur] - b[cur];
  isg = (currentVo > 0);
  if (currentVo) dfs2(cur, cur);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> v >> e;
  fill(fa, fa + N + 1, -1);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < n; j++) cin >> b[j], s[j] = a[j] - b[j];
  for (int i = 0; i < e; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    int f = getFather(u);
    int ff = getFather(v);
    if (ff != f) {
      fa[ff] = f;
      nei[v].push_back(u);
      nei[u].push_back(v);
    }
  }
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    sum = 0;
    dfs(i, i);
    if (sum != 0) return cout << "NO", 0;
  }
  cout << (int)ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].second.first + 1 << ' ' << ans[i].second.second + 1 << ' '
         << ans[i].first << endl;
}
