#include <bits/stdc++.h>
using namespace std;
vector<int> node[301];
int b[301];
int c[301];
int parent[301];
bool visited[301];
stack<int> mo;
stack<int> le;
vector<pair<pair<int, int>, int>> ans;
bool find;
long long cpcum;
void checksum(int now) {
  visited[now] = 1;
  cpcum += (c[now] - b[now]);
  if (c[now] - b[now] > 0)
    mo.push(now);
  else if (c[now] - b[now] < 0)
    le.push(now);
  for (int i = 0; i < node[now].size(); i++) {
    int next = node[now][i];
    if (visited[next]) continue;
    checksum(next);
  }
}
bool dfs(int now, int s, int t) {
  for (int i = 0; i < node[now].size(); i++) {
    int next = node[now][i];
    if (parent[next] != -1) continue;
    parent[next] = now;
    if (next == t) {
      return true;
    }
    if (dfs(next, s, t)) return true;
  }
  return false;
}
void write(int s, int t, int d, int v) {
  if (parent[t] == s) {
    ans.push_back(make_pair(make_pair(s, t), d));
    c[s] -= d;
    c[t] += d;
    return;
  } else if (c[parent[t]] >= d) {
    c[t] += d;
    c[parent[t]] -= d;
    ans.push_back(make_pair(make_pair(parent[t], t), d));
    write(s, parent[t], d, v);
  } else {
    ans.push_back(make_pair(make_pair(parent[t], t), c[parent[t]]));
    int temp = c[parent[t]];
    c[parent[t]] = 0;
    write(s, parent[t], d, v);
    ans.push_back(make_pair(make_pair(parent[t], t), d - temp));
    c[t] += d;
    c[parent[t]] = temp;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, v, e;
  cin >> n >> v >> e;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    sum += c[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    sum -= b[i];
  }
  if (sum != 0) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < e; i++) {
    int u, v;
    cin >> u >> v;
    node[u].push_back(v);
    node[v].push_back(u);
  }
  memset(visited, false, sizeof(visited));
  for (int i = 1; i <= n; i++) {
    if (visited[i] == false) {
      cpcum = 0;
      checksum(i);
      if (cpcum != 0) {
        cout << "NO" << endl;
        return 0;
      }
      while (mo.size() > 0) {
        int s = mo.top();
        int t = le.top();
        for (int i = 0; i <= n; i++) parent[i] = -1;
        parent[s] = 0;
        dfs(s, s, t);
        int d = min(c[s] - b[s], b[t] - c[t]);
        write(s, t, d, v);
        if (c[s] == b[s]) mo.pop();
        if (c[t] == b[t]) le.pop();
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first.first << " " << ans[i].first.second << " "
         << ans[i].second << endl;
  }
  return 0;
}
