#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long linf = 1000000000000000000LL;
const double eps = 0.000001;
const double pi = 3.14159265358979323846;
template <class T>
T abs(T k) {
  return k >= 0 ? k : -k;
}
template <class T>
T sqr(T n) {
  return n * n;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T mod(T a, T b) {
  return (a % b + b) % b;
}
template <class T>
T addmod(T a, T b, T c) {
  return (T)mod((long long)a + b, (long long)c);
}
template <class T>
T mulmod(T a, T b, T c) {
  return (T)mod((long long)a * b, (long long)c);
}
template <class T>
T powmod(T a, T b, T c) {
  return (T)(b ? mulmod(mod((T)sqr((long long)powmod(a, b >> 1, c)), c),
                        b & 1 ? a : 1, c)
               : 1);
}
template <class T>
void maxe(T &a, T b) {
  a = max(a, b);
}
template <class T>
void mine(T &a, T b) {
  a = min(a, b);
}
template <class T>
void mode(T &a, T b) {
  a = mod(a, b);
}
template <class T>
void addmode(T &a, T b, T c) {
  a = addmod(a, b, c);
}
template <class T>
void mulmode(T &a, T b, T c) {
  a = mulmod(a, b, c);
}
template <class T>
void powmode(T &a, T b, T c) {
  a = powmod(a, b, c);
}
void fileio_in_out() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
void fileio_txt() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
const int N = 333;
int test;
int n, m, k, ans;
int a[N], b[N];
pair<int, int> p[N];
int x, y;
vector<int> e[N];
int flag[N], ok[N];
pair<pair<int, int>, int> step[2 * N * N];
int check() {
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) return 0;
  return 1;
}
void trans(int x, int y, int d) {
  step[ans++] = make_pair(make_pair(x, y), d);
  a[x] -= d;
  a[y] += d;
}
void dfs(int x, int w) {
  flag[x] = 1;
  w -= a[x];
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (w > 0 && !flag[y]) {
      if (!ok[y]) {
        dfs(y, w);
        int d = min(w, a[y]);
        w -= d;
        trans(y, x, d);
      } else {
        trans(y, x, w);
        dfs(y, b[y]);
        w = 0;
        if (a[y] < b[y]) {
          w = b[y] - a[y];
          trans(x, y, w);
        }
      }
    }
  }
}
bool cmp(pair<int, int> a, pair<int, int> b) { return a > b; }
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    p[i] = make_pair(b[i], i);
  }
  while (m--) {
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  sort(p + 1, p + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    memset(flag, 0, sizeof(flag));
    dfs(p[i].second, p[i].first);
    ok[p[i].second] = 1;
  }
  if (check()) {
    printf("%d\n", ans);
    for (int i = 0; i < ans; i++)
      printf("%d %d %d\n", step[i].first.first, step[i].first.second,
             step[i].second);
  } else
    puts("NO");
  return 0;
}
