#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},
                        {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
template <class T>
inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
  T ans = a > b ? a : b;
  if (c != -1234567) ans = max1(ans, c);
  if (d != -1234567) ans = max1(ans, d);
  return ans;
}
template <class T>
inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
  T ans = a < b ? a : b;
  if (c != -1234567) ans = min(ans, c);
  if (d != -1234567) ans = min(ans, d);
  return ans;
}
template <class T>
inline T gcd1(T a, T b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd1(b, a % b);
}
template <class T>
inline T lb(T num) {
  return num & (-num);
}
inline int jud(double a, double b) {
  if (abs1(a - b) < eps) return 0;
  if (a < b) return -1;
  return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
  if (na == 1) return 0;
  int be = 0, en = na - 1;
  if (*a <= *(a + na - 1)) {
    if (f_lb == 0)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != 1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != -1)
          en = mid;
        else
          be = mid + 1;
      }
    if (f_small && jud(*(a + be), val) == 1 && be != 0) be--;
    if (!f_small && jud(*(a + be), val) == -1 && be != na - 1) be++;
  } else {
    if (f_lb)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != -1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != 1)
          en = mid;
        else
          be = mid + 1;
      }
    if (!f_small && jud(*(a + be), val) == -1 && be != 0) be--;
    if (f_small && jud(*(a + be), val) == 1 && be != na - 1) be++;
  }
  return be;
}
inline int bitnum(unsigned long long nValue) {
  nValue = ((0xaaaaaaaaaaaaaaaaull & nValue) >> 1) +
           (0x5555555555555555ull & nValue);
  nValue = ((0xccccccccccccccccull & nValue) >> 2) +
           (0x3333333333333333ull & nValue);
  nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue) >> 4) +
           (0x0f0f0f0f0f0f0f0full & nValue);
  nValue = ((0xff00ff00ff00ff00ull & nValue) >> 8) +
           (0x00ff00ff00ff00ffull & nValue);
  nValue = ((0xffff0000ffff0000ull & nValue) >> 16) +
           (0x0000ffff0000ffffull & nValue);
  nValue = ((0xffffffff00000000ull & nValue) >> 32) +
           (0x00000000ffffffffull & nValue);
  return nValue;
}
long long pow(long long n, long long m, long long mod = 0) {
  long long ans = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (mod) ans %= mod;
    }
    k *= k;
    if (mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
const int maxn = 310;
vector<int> edge[maxn];
int f[maxn];
int n, v, e;
int orig[maxn][2];
long long zu[maxn], cntzu, statzu[maxn][2];
int degree[maxn];
int ans[maxn * maxn][3], lans;
int fa[maxn];
int mp[maxn][maxn];
int need[maxn], lneed;
int dfs(int no, int fa, int val) {
  if (orig[no][0] >= val) {
    orig[no][0] -= val;
    return 0;
  }
  val -= orig[no][0];
  for (int i = 0; i < (int)edge[no].size(); i++)
    if (f[edge[no][i]] == 0 && edge[no][i] != fa) {
      int val1 = dfs(edge[no][i], no, val);
      ans[lans][0] = edge[no][i] + 1, ans[lans][1] = no + 1,
      ans[lans++][2] = val - val1;
      orig[no][0] += val - val1;
      val = val1;
      if (val == 0) break;
    }
  orig[no][0] = 0;
  return val;
}
int dfs1(int no, int fa, int val) {
  if (orig[no][0] + val <= v) {
    orig[no][0] += val;
    return val;
  }
  for (int i = 0; i < (int)edge[no].size(); i++)
    if (f[edge[no][i]] == 0 && edge[no][i] != fa) {
      int val1 = dfs1(edge[no][i], no, orig[no][0]);
      ans[lans][1] = edge[no][i] + 1, ans[lans][0] = no + 1,
      ans[lans++][2] = val1;
      orig[no][0] -= val1;
      if (orig[no][0] == 0) break;
    }
  orig[no][0] += val;
  int k = val - max1(orig[no][0] - v, 0);
  orig[no][0] = min1(orig[no][0], v);
  return k;
}
int main() {
  scanf("%d%d%d", &n, &v, &e);
  for (int i = 0; i < n; i++) scanf("%d", orig[i]);
  for (int i = 0; i < n; i++) scanf("%d", orig[i] + 1);
  for (int i = 0; i < e; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    if (mp[a][b]) continue;
    edge[a].push_back(b);
    edge[b].push_back(a);
    mp[a][b] = mp[b][a] = 1;
  }
  memset(zu, -1, sizeof(zu));
  memset(fa, -1, sizeof(fa));
  for (int i = 0; i < n; i++) {
    if (zu[i] == -1) {
      int q[maxn], lq = 0, rq = 0;
      q[rq++] = i;
      zu[i] = cntzu;
      for (; lq != rq; lq++) {
        for (int j = 0; j < (int)edge[q[lq]].size(); j++)
          if (zu[edge[q[lq]][j]] == -1) {
            zu[edge[q[lq]][j]] = cntzu;
            q[rq++] = edge[q[lq]][j];
            fa[edge[q[lq]][j]] = q[lq];
            mp[edge[q[lq]][j]][q[lq]]++;
            mp[q[lq]][edge[q[lq]][j]]++;
          }
      }
      cntzu++;
    }
  }
  for (int i = 0; i < n; i++) {
    statzu[zu[i]][0] += orig[i][0];
    statzu[zu[i]][1] += orig[i][1];
  }
  for (int i = 0; i < cntzu; i++)
    if (statzu[i][0] != statzu[i][1]) {
      cout << "NO" << endl;
      return 0;
    }
  for (int i = 0; i < n; i++)
    for (int j = edge[i].size() - 1; j >= 0; j--) {
      if (mp[i][edge[i][j]] == 1) edge[i].erase(edge[i].begin() + j);
    }
  int q[maxn], lq = 0, rq = 0;
  for (int i = 0; i < n; i++) {
    if (edge[i].size() == 1) q[rq++] = i;
    degree[i] = edge[i].size();
  }
  for (; lq != rq; lq++) {
    lneed = 0;
    if (orig[q[lq]][1] > orig[q[lq]][0]) {
      orig[q[lq]][1] -= orig[q[lq]][0], orig[q[lq]][0] = 0;
      dfs(q[lq], -1, orig[q[lq]][1]);
    } else if (orig[q[lq]][1] < orig[q[lq]][0]) {
      orig[q[lq]][0] -= orig[q[lq]][1], orig[q[lq]][1] = 0;
      dfs1(q[lq], -1, v);
    }
    f[q[lq]] = 1;
    for (int i = 0; i < (int)edge[q[lq]].size(); i++) {
      degree[edge[q[lq]][i]]--;
      if (degree[edge[q[lq]][i]] == 1) q[rq++] = edge[q[lq]][i];
    }
  }
  printf("%d\n", lans);
  for (int i = 0; i < lans; i++) {
    printf("%d %d %d\n", ans[i][0], ans[i][1], ans[i][2]);
  }
  return 0;
}
