#include <bits/stdc++.h>
using namespace std;
const int MAXN = 310, MAXM = 50000 + 10;
vector<pair<pair<int, int>, int> > CC;
struct Graph {
  int id, next;
} g[MAXN * 2];
int n, m, st[MAXN], a[MAXN], b[MAXN], v, f[MAXN], tot, cnt[MAXN];
pair<int, int> e[MAXM];
int getf(int first) {
  if (f[first] == first) return first;
  f[first] = getf(f[first]);
  return f[first];
}
bool Union(int first, int second) {
  int fx = getf(first), fy = getf(second);
  if (fx == fy) return false;
  f[fx] = fy;
  return true;
}
void Add(int first, int second) {
  g[tot].id = second, g[tot].next = st[first], st[first] = tot++;
  g[tot].id = first, g[tot].next = st[second], st[second] = tot++;
}
void init() {
  scanf("%d%d%d", &n, &v, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int j = 1; j <= n; ++j) scanf("%d", &b[j]);
  for (int i = 1; i <= n; ++i) f[i] = i;
  memset(st, -1, sizeof(st));
  for (int i = 1; i <= m; ++i) {
    int first, second;
    scanf("%d%d", &first, &second);
    e[i] = make_pair(first, second);
    if (Union(first, second)) Add(first, second);
  }
  for (int i = 1; i <= n; ++i) cnt[getf(i)] += a[i] - b[i];
  for (int i = 1; i <= n; ++i)
    if (cnt[i] != 0) puts("NO"), exit(0);
}
int fa[MAXN];
bool used[MAXN];
int Gain(int first, int fx, int res) {
  if (res == 0) return 0;
  if (res > 0 && a[first] >= res) {
    a[fx] += res, a[first] -= res;
    CC.push_back(make_pair(make_pair(first, fx), res));
    return -res;
  }
  if (res < 0 && v + res >= a[first]) {
    a[fx] += res, a[first] -= res;
    CC.push_back(make_pair(make_pair(fx, first), -res));
    return -res;
  }
  int flow = (res > 0) ? (res - a[first]) : ((v + res) - a[first]);
  for (int i = st[first]; i != -1; i = g[i].next)
    if (g[i].id != fx && !used[g[i].id]) {
      int F = Gain(g[i].id, first, flow);
      flow += F;
      if (flow == 0) break;
    }
  res -= flow;
  a[fx] += res, a[first] -= res;
  if (res + flow > 0) {
    if (res != 0) CC.push_back(make_pair(make_pair(first, fx), res));
  } else if (res != 0)
    CC.push_back(make_pair(make_pair(fx, first), -res));
  return -res;
}
void DFS(int first) {
  for (int i = st[first]; i != -1; i = g[i].next)
    if (g[i].id != fa[first]) fa[g[i].id] = first, DFS(g[i].id);
  used[first] = true;
  if (fa[first])
    Gain(fa[first], first, b[first] - a[first]);
  else if (a[first] != b[first])
    puts("NO"), exit(0);
}
void solve() {
  for (int i = 1; i <= n; ++i)
    if (!used[i]) DFS(i);
  cout << CC.size() << endl;
  for (int i = 0; i < (int)CC.size(); ++i)
    cout << CC[i].first.first << " " << CC[i].first.second << " "
         << CC[i].second << endl;
}
int main() {
  init();
  solve();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
