#include <bits/stdc++.h>
using namespace std;
int n, m, vv, a[333], b[333], f[333], d[333], x, y;
vector<int> v[333];
vector<pair<int, pair<int, int> > > ans;
pair<int, int> q[333];
void transfer(int x, int y, int z) {
  ans.push_back(make_pair(z, make_pair(x, y)));
  a[x] -= z;
  a[y] += z;
}
void dai(int x, int o) {
  f[x] = 1;
  o -= a[x];
  for (int i = 0; i < v[x].size(); i++)
    if (!f[v[x][i]] && o > 0) {
      if (!d[v[x][i]]) {
        dai(v[x][i], o);
        int t = min(a[v[x][i]], o);
        o -= t;
        transfer(v[x][i], x, t);
      } else {
        transfer(v[x][i], x, o);
        dai(v[x][i], b[v[x][i]]);
        o = 0;
        if (a[v[x][i]] < b[v[x][i]]) {
          o = b[v[x][i]] - a[v[x][i]];
          transfer(x, v[x][i], b[v[x][i]] - a[v[x][i]]);
        }
      }
    }
}
int main() {
  cin >> n >> vv >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 0; i < n; i++) q[i] = make_pair(-b[i], i);
  sort(q, q + n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) f[j] = 0;
    int e = q[i].second;
    dai(e, b[e]);
    d[e] = 1;
  }
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) {
      puts("NO");
      return 0;
    }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].second.first + 1 << " " << ans[i].second.second + 1 << " "
         << ans[i].first << endl;
  return 0;
}
