#include <bits/stdc++.h>
using namespace std;
long long int aa[601];
long long int b[600];
long long int n, v, e;
vector<int> adjlist[301];
bool unfinished[301];
int parent[301];
stringstream ostrs;
int olen;
void _transfuse(int from, int to, long long int amount) {
  if (parent[from] == 0) return;
  if (amount + b[parent[from]] <= v) {
    b[parent[from]] += amount;
    b[from] -= amount;
    ostrs << from << " " << parent[from] << " " << amount << endl;
    olen++;
    _transfuse(parent[from], to, amount);
  } else if (b[parent[from]] >= amount) {
    olen++;
    _transfuse(parent[from], to, amount);
    b[parent[from]] += amount;
    b[from] -= amount;
    ostrs << from << " " << parent[from] << " " << amount << endl;
  } else {
    olen += 2;
    ostrs << from << " " << parent[from] << " " << v - b[parent[from]] << endl;
    long long int temp = amount - (v - b[parent[from]]);
    b[from] -= v - b[parent[from]];
    b[parent[from]] = v;
    _transfuse(parent[from], to, amount);
    b[from] -= temp;
    b[parent[from]] += temp;
    ostrs << from << " " << parent[from] << " " << temp << endl;
  }
}
void transfuse(int v1, int v2) {
  long long int of = b[v1] - aa[v1];
  long long int uf = aa[v2] - b[v2];
  if (of >= uf) {
    _transfuse(v1, v2, uf);
  } else {
    _transfuse(v1, v2, of);
  }
}
int main() {
  long long int cs = 0;
  cin >> n >> v >> e;
  bool pos = true;
  deque<int> todo;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (aa[i] > v) pos = false;
    cs -= b[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> aa[i];
    if (aa[i] > v) pos = false;
    if (b[i] < aa[i]) {
      todo.push_back(i);
    }
    cs += aa[i];
  }
  if (cs != 0) pos = false;
  if (!pos) {
    cout << "NO";
    return 0;
  }
  int v1, v2;
  for (int i = 0; i < e; i++) {
    cin >> v1 >> v2;
    adjlist[v1].push_back(v2);
    adjlist[v2].push_back(v1);
  }
  bool done = false;
  while (!todo.empty()) {
    int e = todo.front();
    todo.pop_front();
    fill(parent, parent + n + 1, -1);
    deque<int> q;
    q.push_back(e);
    parent[e] = 0;
    bool fail = true;
    while (!q.empty()) {
      int nod = q.front();
      q.pop_front();
      if (b[nod] > aa[nod]) {
        transfuse(nod, e);
        if (b[nod] < aa[nod]) {
          todo.push_back(nod);
        } else if (b[e] < aa[e]) {
          todo.push_back(e);
        }
        fail = false;
        break;
      }
      for (vector<int>::iterator j = adjlist[nod].begin();
           j != adjlist[nod].end(); j++) {
        if (parent[*j] == -1) {
          q.push_back(*j);
          parent[*j] = nod;
        }
      }
    }
    if (fail) {
      cout << "NO";
      return 0;
    }
  }
  cout << olen << endl;
  cout << ostrs.str();
  return 0;
}
