#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) {
  a.first += b.first;
  a.second += b.second;
  return a;
}
pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) {
  a.first -= b.first;
  a.second -= b.second;
  return a;
}
template <class T, class U>
bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {
  return a.second < b.second;
}
template <class T>
T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}
template <class T>
pair<T, T> ext_gcd(T a, T b) {
  T a0 = 1, a1 = 0, b0 = 0, b1 = 1;
  if (a < 0) {
    a = -a;
    a0 = -1;
  }
  if (b < 0) {
    b = -b;
    b1 = -1;
  }
  while (b) {
    T t, q = a / b;
    t = b;
    b = a - b * q;
    a = t;
    t = b0;
    b0 = a0 - b0 * q;
    a0 = t;
    t = b1;
    b1 = a1 - b1 * q;
    a1 = t;
  }
  return make_pair(a0, a1);
}
inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; }
class DisjointSet {
 public:
  int n;
  int *rep, *rank;
  DisjointSet(int _n) : n(_n) {
    rep = new int[n];
    rank = new int[n];
    for (int i = 0; i < n; i++) rep[i] = i;
  }
  ~DisjointSet() {
    delete[] rep;
    delete[] rank;
  }
  int getrep(int v) {
    if (rep[v] != v) rep[v] = getrep(rep[v]);
    return rep[v];
  }
  bool merge(int v, int u) {
    v = getrep(v);
    u = getrep(u);
    if (v == u) return 0;
    if (rank[v] < rank[u]) {
      rep[v] = u;
    } else {
      rep[u] = v;
      if (rank[v] == rank[u]) rank[v]++;
    }
    return 1;
  }
};
int n, cap, ne;
int cur[330], goal[330];
vector<int> adj[330];
vector<int> order;
vector<pair<pair<int, int>, int> > seq;
bool vis[330], inactive[330];
void dfs(int v) {
  vis[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (vis[u]) continue;
    dfs(u);
  }
  order.push_back(v);
}
int suck(int v, int req, int p, bool fixed) {
  vis[v] = 1;
  int ret = 0;
  if (!fixed) {
    int a = min(cur[v], req);
    ret += a;
    cur[v] -= a;
    req -= a;
  }
  for (int i = 0; req && i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (vis[u]) continue;
    if (inactive[u]) continue;
    int uret = suck(u, req, v, 0);
    ret += uret;
    req -= uret;
  }
  if (!fixed) seq.push_back(make_pair(make_pair(v, p), ret));
  return ret;
}
int push(int v, int req, int p, bool fixed) {
  vis[v] = 1;
  int ret = 0;
  if (!fixed) {
    int a = min(cap - cur[v], req);
    ret += a;
    cur[v] += a;
    req -= a;
  }
  for (int i = 0; req && i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (vis[u]) continue;
    if (inactive[u]) continue;
    int uret = push(u, req, v, 0);
    ret += uret;
    req -= uret;
    seq.push_back(make_pair(make_pair(v, u), uret));
  }
  return ret;
}
bool solve() {
  for (int v = 1; v <= n; v++)
    if (!vis[v]) dfs(v);
  for (int o = 0; o < n; o++) {
    int v = order[o];
    memset(vis, 0, sizeof(vis));
    if (cur[v] > goal[v]) {
      int amt = cur[v] - goal[v];
      int ret = push(v, amt, -1, 1);
      if (ret != amt) return 0;
    } else if (cur[v] < goal[v]) {
      int amt = goal[v] - cur[v];
      int ret = suck(v, amt, -1, 1);
      if (ret != amt) return 0;
    }
    inactive[v] = 1;
  }
  printf("%d\n", (int)seq.size());
  for (int i = 0; i < seq.size(); i++)
    printf("%d %d %d\n", seq[i].first.first, seq[i].first.second,
           seq[i].second);
  ;
  return 1;
}
int main(void) {
  scanf("%d %d %d", &(n), &(cap), &(ne));
  DisjointSet djs(n + 1);
  for (int i = 1; i <= n; i++) scanf("%d", &(cur[i]));
  for (int i = 1; i <= n; i++) scanf("%d", &(goal[i]));
  for (int i = 0; i < ne; i++) {
    int v, u;
    scanf("%d %d", &(v), &(u));
    if (djs.getrep(v) == djs.getrep(u)) continue;
    djs.merge(v, u);
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  if (!solve()) puts("NO");
  return 0;
}
