#include <bits/stdc++.h>
using namespace std;
const unsigned int ooi = 1 << 30;
const long long ool = 1ll << 60;
const int Maxn = 330;
const int Maxm = 50505;
struct edges {
  int to, next;
  long long c;
  edges(int _to = 0, int _next = 0, long long _c = 0)
      : to(_to), next(_next), c(_c) {}
} edg[Maxm << 1];
int fir[Maxn] = {0}, tot = 1;
int v[Maxn] = {0}, cur[Maxn] = {0};
void Adde(int a, int b, long long c, long long nc = 0) {
  edg[++tot] = edges(b, fir[a], c);
  fir[a] = tot;
  edg[++tot] = edges(a, fir[b], nc);
  fir[b] = tot;
}
bool bfs(int st, int ed) {
  static queue<int> q;
  memset(v, 0, sizeof(v));
  q.push(st);
  v[st] = 1;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int e = fir[now]; e; e = edg[e].next) {
      int to = edg[e].to;
      if (v[to] || !edg[e].c) continue;
      v[to] = v[now] + 1;
      q.push(to);
    }
  }
  return v[ed];
}
long long dfs(int now, int ed, long long dist = ool) {
  if (now == ed || !dist) return dist;
  long long f = 0;
  for (int &e = cur[now]; e; e = edg[e].next) {
    int to = edg[e].to;
    if (!edg[e].c || v[to] != v[now] + 1) continue;
    long long tmp = dfs(to, ed, min(dist, edg[e].c));
    if (tmp) {
      f += tmp;
      edg[e].c -= tmp;
      edg[e ^ 1].c += tmp;
      dist -= tmp;
      if (!dist) return f;
    }
  }
  return f;
}
long long dinic(int st, int ed, int nst, int ned) {
  long long re = 0;
  while (bfs(st, ed)) {
    for (int i = nst; i <= ned; i++) cur[i] = fir[i];
    while (long long d = dfs(st, ed)) re += d;
  }
  return re;
}
bool linked[Maxn][Maxn] = {0};
int stv[Maxn] = {0}, edv[Maxn] = {0};
int nowv[Maxn] = {0};
int ans[Maxn * Maxn * 3][3] = {0}, edans = 0;
int main() {
  int n, V, e;
  cin >> n >> V >> e;
  long long sumf = 0;
  for (int i = 1; i <= n; i++) cin >> stv[i];
  for (int i = 1; i <= n; i++) cin >> edv[i];
  for (int a, b, i = 1; i <= e; i++) {
    cin >> a >> b;
    if (a == b) continue;
    if (!linked[a][b]) {
      Adde(a, b, ool, ool);
      linked[a][b] = linked[b][a] = 1;
    }
  }
  int alledges = tot;
  int s = 0, t = n + 1;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    nowv[i] = stv[i];
    int delta = edv[i] - stv[i];
    sum += delta;
    sumf += abs(delta);
    if (delta < 0)
      Adde(s, i, -delta);
    else if (delta > 0)
      Adde(i, t, delta);
  }
  if (sum) {
    cout << "NO" << endl;
    return 0;
  }
  if (sumf != 2 * dinic(s, t, s, t)) {
    cout << "NO" << endl;
    return 0;
  };
  while (true) {
    bool flag = 0;
    for (int e = 2; e <= alledges; e += 2) {
      if (edg[e].c == ool) continue;
      int b = edg[e].to, a = edg[e ^ 1].to;
      if (edg[e].c < ool) {
        if (!nowv[a] || nowv[b] == V) continue;
        int f = min((long long)min(nowv[a], V - nowv[b]), ool - edg[e].c);
        ans[++edans][0] = a;
        ans[edans][1] = b;
        ans[edans][2] = f;
        nowv[a] -= f;
        nowv[b] += f;
        edg[e].c += f;
        edg[e ^ 1].c -= f;
        flag = 1;
      } else {
        if (!nowv[b] || nowv[a] == V) continue;
        int f = min((long long)min(nowv[b], V - nowv[a]), edg[e].c - ool);
        ans[++edans][0] = b;
        ans[edans][1] = a;
        ans[edans][2] = f;
        nowv[b] -= f;
        nowv[a] += f;
        edg[e].c -= f;
        edg[e ^ 1].c += f;
        flag = 1;
      }
    }
    if (!flag) break;
    if (edans >= 2 * n * n) break;
  }
  for (int e = 2; e <= alledges; e += 2)
    if (edg[e].c != ool) {
      cout << "NO" << endl;
      return 0;
    }
  cout << edans << endl;
  for (int i = 1; i <= edans; i++)
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << endl;
  return 0;
}
