#include <bits/stdc++.h>
using namespace std;
const int NMax = 400;
int G[NMax][NMax];
int N, V, E, A[NMax], B[NMax], father[NMax], father1[NMax];
vector<int> cur;
int Find(int a) {
  int R;
  for (R = a; father[R] != -1; R = father[R])
    ;
  return R;
}
int F[NMax], have[NMax];
int DFS(int a, int cnt) {
  int last = cnt;
  have[a] = 1;
  for (int i = 0; i < cur.size(); i++)
    if (!have[cur[i]] && father1[cur[i]] == -1 && G[a][cur[i]]) {
      father1[cur[i]] = a;
      int take = DFS(cur[i], cnt);
      cnt -= take;
    }
  if (A[a] < B[a]) {
    int take = min(cnt, B[a] - A[a]);
    cnt -= take;
    A[a] += take;
  }
  return F[a] = last - cnt;
}
vector<pair<pair<int, int>, int> > Q;
void getans(int a) {
  for (int i = 0; i < cur.size(); i++)
    if (father1[cur[i]] == a) {
      if (F[cur[i]] + A[cur[i]] <= V) {
        if (F[cur[i]] > 0)
          Q.push_back(make_pair(make_pair(a, cur[i]), F[cur[i]]));
        getans(cur[i]);
      }
    }
  for (int i = 0; i < cur.size(); i++)
    if (father1[cur[i]] == a) {
      if (F[cur[i]] + A[cur[i]] > V) {
        if (V - A[cur[i]] > 0)
          Q.push_back(make_pair(make_pair(a, cur[i]), V - A[cur[i]]));
        getans(cur[i]);
        if (F[cur[i]] - (V - A[cur[i]]) > 0)
          Q.push_back(
              make_pair(make_pair(a, cur[i]), F[cur[i]] - (V - A[cur[i]])));
      }
    }
}
int main() {
  memset(father, -1, sizeof(father));
  scanf("%d%d%d", &N, &V, &E);
  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 <= E; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x][y] = G[y][x] = 1;
    int x1 = Find(x), x2 = Find(y);
    if (x1 != x2) father[x1] = x2;
  }
  for (int i = 1; i <= N; i++)
    if (father[i] == -1) {
      long long cnta = 0, cntb = 0;
      cur.clear();
      for (int j = 1; j <= N; j++)
        if (Find(j) == i) {
          cur.push_back(j);
          cnta += A[j];
          cntb += B[j];
        }
      if (cnta != cntb) {
        puts("NO");
        return 0;
      }
      for (int j = 0; j < cur.size(); j++)
        if (A[cur[j]] > B[cur[j]]) {
          memset(have, 0, sizeof(have));
          memset(father1, -1, sizeof(father1));
          DFS(cur[j], A[cur[j]] - B[cur[j]]);
          getans(cur[j]);
          A[cur[j]] = B[cur[j]];
        }
    }
  printf("%d\n", (int)Q.size());
  for (int i = 0; i < Q.size(); i++)
    printf("%d %d %d\n", Q[i].first.first, Q[i].first.second, Q[i].second);
  return 0;
}
