#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
template <class T>
void read(T &x) {
  char ch;
  while ((ch = getchar()) && !isdigit(ch))
    ;
  x = ch - '0';
  while ((ch = getchar()) && isdigit(ch)) x = x * 10 + ch - '0';
}
struct point {
  int x, y;
  point() {}
  point(int _x, int _y) : x(_x), y(_y) {}
};
struct flow {
  int x, y, c;
  flow() {}
  flow(int _x, int _y, int _c) : x(_x), y(_y), c(_c) {}
};
const int N = 400;
vector<int> E[N];
long long sum;
int a[N], b[N], fa[N], n, v, m, vis[N], al;
long long Left[N], all[N];
vector<flow> Ans;
void dfs_check(int w, int Fa) {
  sum += (long long)(b[w] - a[w]);
  for (int i = 0; i < E[w].size(); i++)
    if (E[w][i] != Fa) dfs_check(E[w][i], w);
}
int g_f(int x) { return fa[x] == x ? x : fa[x] = g_f(fa[x]); }
void dfs_all(int w, int Fa) {
  all[w] = v - a[w];
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      dfs_all(E[w][i], w);
      all[w] += all[E[w][i]];
    }
}
void dfs_Left(int w, int Fa) {
  Left[w] = a[w];
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      dfs_Left(E[w][i], w);
      Left[w] += Left[E[w][i]];
    }
}
void push(int w, int c, int Fa) {
  if (v - a[w] >= c) {
    Ans.push_back(flow(Fa, w, c));
    a[Fa] -= c;
    a[w] += c;
    return;
  }
  int now = c, T = c - (v - a[w]);
  if (a[w] != v)
    Ans.push_back(flow(Fa, w, v - a[w])), a[Fa] -= v - a[w], a[w] = v;
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      int can = min(all[E[w][i]], (long long)now);
      push(E[w][i], can, w);
      now -= can;
      if (!now) break;
    }
  Ans.push_back(flow(Fa, w, T));
  a[Fa] -= T;
  a[w] += T;
}
void pull(int w, int c, int Fa) {
  if (a[w] >= c) {
    Ans.push_back(flow(w, Fa, c));
    a[Fa] += c;
    a[w] -= c;
    return;
  }
  int now = c, T = c - a[w];
  if (a[w]) Ans.push_back(flow(w, Fa, a[w])), a[Fa] += a[w], a[w] = 0;
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      int can = min(Left[E[w][i]], (long long)now);
      pull(E[w][i], can, w);
      now -= can;
      if (!now) break;
    }
  Ans.push_back(flow(w, Fa, T));
  a[Fa] += T;
  a[w] -= T;
}
void work(int x) {
  if (a[x] == b[x])
    return;
  else if (a[x] > b[x]) {
    dfs_all(x, 0);
    int now = a[x] - b[x];
    for (int i = 0; i < E[x].size(); i++)
      if (!vis[E[x][i]]) {
        int c = min(all[E[x][i]], (long long)now);
        push(E[x][i], c, x);
        now -= c;
        if (!now) break;
      }
  } else if (a[x] < b[x]) {
    dfs_Left(x, 0);
    int now = b[x] - a[x];
    for (int i = 0; i < E[x].size(); i++)
      if (!vis[E[x][i]]) {
        int c = min(Left[E[x][i]], (long long)now);
        pull(E[x][i], c, x);
        now -= c;
        if (!now) break;
      }
  }
}
int rd[N];
queue<int> Q;
int main() {
  scanf("%d%d%d", &n, &v, &m);
  int x, y;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (g_f(x) != g_f(y))
      fa[g_f(x)] = g_f(y), E[x].push_back(y), E[y].push_back(x), rd[x]++,
      rd[y]++;
  }
  for (int i = 1; i <= n; i++) {
    dfs_check(i, 0);
    if (sum != 0) {
      puts("NO");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    if (rd[i] == 1) Q.push(i);
  while (Q.size()) {
    int x = Q.front();
    vis[x] = 1;
    work(x);
    Q.pop();
    for (int i = 0; i < E[x].size(); i++) {
      rd[E[x][i]]--;
      if (rd[E[x][i]] == 1) Q.push(E[x][i]);
    }
  }
  printf("%d\n", Ans.size());
  for (int i = 0; i < Ans.size(); i++)
    printf("%d %d %d\n", Ans[i].x, Ans[i].y, Ans[i].c);
}
