#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v);
const int N = 340;
bool color[N];
vector<int> adj[N];
int n;
int cap;
int parent[N];
int has[N];
int desired[N];
int deg[N];
bool solved[N];
long long dfs(int v) {
  if (!color[v]) return 0;
  color[v] = false;
  long long res = has[v] - desired[v];
  for (__typeof((adj[v]).begin()) u = (adj[v]).begin(); u != (adj[v]).end();
       u++) {
    if (color[*u]) {
      parent[*u] = v;
      deg[v]++;
      res += dfs(*u);
    }
  }
  return res;
}
bool check() {
  for (int i = 0; i < (n); i++) {
    parent[i] = -1;
    color[i] = true;
    deg[i] = 0;
  }
  for (int i = 0; i < (n); i++) {
    long long x = dfs(i);
    if (x != 0) return false;
  }
  return true;
}
struct tr {
  int a, b, c;
  tr(int x, int y, int z) {
    a = x;
    b = y;
    c = z;
  }
};
vector<tr> ans;
void send(int a, int b, int k) {
  if (k == 0) return;
  ans.push_back(tr(a + 1, b + 1, k));
  has[a] -= k;
  has[b] += k;
}
void out(int v, int cnt) {
  if (color[v] == false) return;
  color[v] = false;
  cnt = min(cnt, has[v]);
  for (__typeof((adj[v]).begin()) u = (adj[v]).begin(); u != (adj[v]).end();
       u++) {
    if (color[*u] == false) continue;
    out(*u, cnt);
    int tmp = min(cap - has[*u], cnt);
    send(v, *u, tmp);
    cnt -= tmp;
  }
}
void outward(int v, int cnt) {
  for (int i = 0; i < (n); i++) color[i] = !solved[i];
  out(v, cnt);
}
void in(int v, int cnt) {
  if (color[v] == 0) return;
  color[v] = false;
  cnt = min(cnt, cap - has[v]);
  for (__typeof((adj[v]).begin()) u = (adj[v]).begin(); u != (adj[v]).end();
       u++) {
    if (color[*u] == false) continue;
    in(*u, cnt);
    int tmp = min(has[*u], cnt);
    send(*u, v, tmp);
    cnt -= tmp;
  }
}
void inward(int v, int cnt) {
  for (int i = 0; i < (n); i++) color[i] = !solved[i];
  in(v, cnt);
}
void solve(int v) {
  if (has[v] > desired[v]) {
    outward(v, has[v] - desired[v]);
  } else {
    inward(v, desired[v] - has[v]);
  }
  solved[v] = true;
}
int main() {
  int m;
  scanf("%d %d %d", &n, &cap, &m);
  for (int i = 0; i < (n); i++) scanf("%d", &has[i]);
  for (int i = 0; i < (n); i++) scanf("%d", &desired[i]);
  for (int i = 0; i < (m); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if (!check()) {
    printf("NO\n");
    return 0;
  }
  for (int i = 0; i < (n); i++) solved[i] = false;
  queue<int> q;
  for (int i = 0; i < (n); i++) {
    if (deg[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    solve(v);
    if (parent[v] != -1) {
      if ((--deg[parent[v]]) == 0) {
        q.push(parent[v]);
      }
    }
  }
  printf("%d\n", ans.size());
  for (__typeof((ans).begin()) t = (ans).begin(); t != (ans).end(); t++) {
    printf("%d %d %d\n", t->a, t->b, t->c);
  }
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  bool first = true;
  for (__typeof((v).begin()) x = (v).begin(); x != (v).end(); x++) {
    if (!first) {
      o << ", ";
    }
    o << *x;
    first = false;
  }
  o << "]";
  return o;
}
