#include <bits/stdc++.h>
using namespace std;
inline int Get_Int() {
  int Num = 0, Flag = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') Flag = -Flag;
  } while (ch < '0' || ch > '9');
  do {
    Num = Num * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return Num * Flag;
}
int N, M, Limit, Total, K;
int Now[305], End[305], Ans[305 * 305 * 2][3];
bool Visited[305], Deleted[305];
vector<int> To[305];
int BFS(int S) {
  int Now;
  memset(Visited, false, sizeof(Visited));
  Visited[S] = true;
  queue<int> Queue;
  Queue.push(S);
  while (!Queue.empty()) {
    Now = Queue.front();
    Queue.pop();
    for (typeof(To[Now].begin()) it = To[Now].begin(); it != To[Now].end();
         ++it)
      if (!Visited[*it] && !Deleted[*it]) {
        Visited[*it] = true;
        Queue.push(*it);
      }
  }
  return Now;
}
int DFS(int x, int Need) {
  int Rest = Need;
  if (!Need) return 0;
  Visited[x] = true;
  for (typeof(To[x].begin()) it = To[x].begin(); it != To[x].end(); ++it)
    if (!Visited[*it] && !Deleted[*it]) {
      int Increment;
      if (Need > 0)
        Increment = min(Rest, Now[*it]);
      else
        Increment = max(Rest, Now[*it] - Limit);
      Increment += DFS(*it, Rest - Increment);
      Rest -= Increment;
      ++K;
      Ans[K][0] = *it;
      Ans[K][1] = x;
      Ans[K][2] = Increment;
      Now[*it] -= Increment;
      Now[x] += Increment;
      if (!Rest) return Need;
    }
  return Need - Rest;
}
int main() {
  cin >> N >> Limit >> M;
  for (int i = 1; i <= N; ++i) Now[i] = Get_Int();
  for (int i = 1; i <= N; ++i) End[i] = Get_Int();
  for (int i = 1; i <= M; ++i) {
    int x = Get_Int(), y = Get_Int();
    To[x].push_back(y);
    To[y].push_back(x);
  }
  for (int i = 1; i <= N; ++i)
    while (!Deleted[i]) {
      int S = BFS(i);
      Total = 0;
      memset(Visited, false, sizeof(Visited));
      int Flow = End[S] - Now[S];
      if (Flow != DFS(S, End[S] - Now[S])) {
        printf("NO\n");
        return 0;
      }
      Deleted[S] = true;
    }
  cout << K << endl;
  for (int i = 1; i <= K; ++i)
    if (Ans[i][2] > 0)
      printf("%d %d %d\n", Ans[i][0], Ans[i][1], Ans[i][2]);
    else
      printf("%d %d %d\n", Ans[i][1], Ans[i][0], -Ans[i][2]);
  return 0;
}
