#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300;
int n, v, e, a[MAXN], b[MAXN];
vector<int> edge[MAXN], child[MAXN];
bool tag[MAXN];
vector<vector<int> > comp;
long long sum[MAXN];
void dfs(int u) {
  tag[u] = true;
  comp.back().push_back(u);
  for (typeof((edge[u]).begin()) it = (edge[u]).begin(); it != (edge[u]).end();
       it++)
    if (!tag[*it]) dfs(*it);
}
bool possible() {
  for (typeof((comp).begin()) it = (comp).begin(); it != (comp).end(); it++) {
    long long sum = 0;
    for (typeof((*it).begin()) jt = (*it).begin(); jt != (*it).end(); jt++)
      sum += a[*jt] - b[*jt];
    if (sum) return false;
  }
  return true;
}
void build(int u) {
  tag[u] = true;
  sum[u] = a[u] - b[u];
  for (typeof((edge[u]).begin()) it = (edge[u]).begin(); it != (edge[u]).end();
       it++)
    if (!tag[*it]) {
      child[u].push_back(*it);
      build(*it);
      sum[u] += sum[*it];
    }
}
vector<pair<pair<int, int>, int> > answer;
int add(int x, int y, int flow) {
  flow = min(flow, min(a[x], v - a[y]));
  if (flow > 0) {
    answer.push_back(make_pair(make_pair(x, y), flow));
    a[x] -= flow;
    a[y] += flow;
  }
  return max(flow, 0);
}
void fix(int u) {
  for (typeof((child[u]).begin()) it = (child[u]).begin();
       it != (child[u]).end(); it++)
    if (sum[*it] > 0) {
      fix(*it);
      int delta = add(*it, u, min(sum[*it], (long long)v));
      sum[*it] -= delta;
    }
  for (typeof((child[u]).begin()) it = (child[u]).begin();
       it != (child[u]).end(); it++)
    if (sum[*it] <= 0) {
      int delta = add(u, *it, min(-sum[*it], (long long)v));
      sum[*it] += delta;
      fix(*it);
    }
}
int main() {
  scanf("%d%d%d", &n, &v, &e);
  for (int i = (0); i < (n); i++) scanf("%d", &a[i]);
  for (int i = (0); i < (n); i++) scanf("%d", &b[i]);
  for (int _ = (0); _ < (e); _++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  for (int i = (0); i < (n); i++)
    if (!tag[i]) {
      comp.push_back(vector<int>());
      dfs(i);
    }
  if (possible()) {
    memset(tag, 0, sizeof(tag));
    for (typeof((comp).begin()) it = (comp).begin(); it != (comp).end(); it++) {
      build(it->front());
      while (true) {
        bool fixed = true;
        for (typeof((*it).begin()) jt = (*it).begin(); jt != (*it).end(); jt++)
          if (a[*jt] != b[*jt]) {
            fixed = false;
            break;
          }
        if (fixed) break;
        fix(it->front());
      }
    }
    printf("%d\n", ((int)(answer).size()));
    for (typeof((answer).begin()) it = (answer).begin(); it != (answer).end();
         it++)
      printf("%d %d %d\n", it->first.first + 1, it->first.second + 1,
             it->second);
  } else {
    puts("NO");
  }
  return 0;
}
