#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const long long inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool checkBit(long long n, long long i) { return n & (1LL << i); }
inline long long setBit(long long n, long long i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, long long i) {
  return n & (~(1LL << i));
}
long long dx[] = {0, 0, +1, -1};
long long dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInverse(b));
}
const long long N = 310, M = 50100;
long long vis[N], par[N], a[N], b[N], sum[N];
vector<long long> adjList[N];
vector<long long> path;
vector<pair<long long, long long> > store[N];
vector<pair<pair<long long, long long>, long long> > ans;
long long find_set(long long x) {
  if (x != par[x]) return par[x] = find_set(par[x]);
  return x;
}
void NO() {
  cout << "NO" << '\n';
  exit(0);
}
void mkpath(long long l, long long r) {
  path.clear();
  memset(vis, 0, sizeof(vis));
  queue<long long> bfs;
  bfs.push(l);
  memset(vis, 0, sizeof(vis));
  memset(par, -1, sizeof(par));
  vis[l] = true;
  while (!vis[r]) {
    long long u = bfs.front();
    bfs.pop();
    for (auto v : adjList[u]) {
      ;
      if (vis[v]) continue;
      vis[v] = true;
      bfs.push(v);
      par[v] = u;
    }
  };
  for (long long u = r; u != -1LL; u = par[u]) path.emplace_back(u);
  ;
}
void solve(long long idx, long long val) {
  if (idx == 0) return;
  ans.emplace_back(make_pair(make_pair(path[idx - 1], path[idx]),
                             min(a[path[idx - 1]], val)));
  solve(idx - 1, val);
  if (val > a[path[idx - 1]])
    ans.emplace_back(make_pair(make_pair(path[idx - 1], path[idx]),
                               max(0LL, val - a[path[idx - 1]])));
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, v, e;
  cin >> n >> v >> e;
  long long sum_a = 0, sum_b = 0;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long i = 0; i < n; ++i) cin >> b[i];
  for (long long i = 0; i < n; ++i) par[i] = i;
  for (long long i = 0; i < e; ++i) {
    long long u, v;
    cin >> u >> v;
    --u;
    --v;
    adjList[u].emplace_back(v);
    adjList[v].emplace_back(u);
    long long u_p = find_set(u);
    long long v_p = find_set(v);
    par[u_p] = v_p;
  }
  for (long long i = 0; i < n; ++i) {
    store[find_set(i)].emplace_back(pair<long long, long long>(b[i] - a[i], i));
    sum[par[i]] += b[i] - a[i];
  }
  for (long long i = 0; i < n; ++i) {
    ;
    if (sum[i]) NO();
    sort(store[i].begin(), store[i].end(),
         greater<pair<long long, long long> >());
    ;
    long long l = 0, r = store[i].size() - 1LL;
    while (l < r) {
      long long val = min(abs(store[i][l].first), abs(store[i][r].first));
      mkpath(store[i][l].second, store[i][r].second);
      ;
      solve(path.size() - 1, val);
      a[store[i][l].second] += val;
      a[store[i][r].second] -= val;
      store[i][l].first -= val;
      store[i][r].first += val;
      if (!store[i][l].first) ++l;
      if (!store[i][r].first) --r;
    }
  }
  cout << ans.size() << '\n';
  for (auto it : ans)
    cout << it.first.first + 1 << " " << it.first.second + 1 << " " << it.second
         << '\n';
  return 0;
}
