#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
vector<pair<pair<int, int>, int> > tubes;
int vis[303];
vector<int> g[303];
int v;
int a[303], b[303];
long long A, B;
int n, e;
void dfs(int now) {
  vis[now] = 1;
  A += a[now];
  B += b[now];
  for (auto it : g[now]) {
    if (!vis[it]) dfs(it);
  }
}
int fa[303];
vector<int> order;
vector<int> tree_edges[303];
void build(int now, int pre = 0) {
  fa[now] = pre;
  vis[now] = 2;
  order.push_back(now);
  for (auto it : g[now]) {
    if (vis[it] != 2) {
      tree_edges[now].push_back(it);
      tree_edges[it].push_back(now);
      build(it, now);
    }
  }
}
bool updated[303];
void pull_up(int index) {
  for (auto it : tree_edges[index]) {
    if (it != fa[index]) {
      int can = min(v - a[index], a[it]);
      if (updated[it]) can = min(can, a[it] - b[it]);
      if (can) tubes.push_back(make_pair(make_pair(it, index), can));
      a[it] -= can;
      a[index] += can;
      pull_up(it);
    }
  }
}
void work(int root) {
  order.clear();
  build(root);
  for (auto it : order) {
    int to = fa[it];
    int from = it;
    while (to) {
      int can = v - a[to];
      if (min(a[from], can)) {
        tubes.push_back(make_pair(make_pair(from, to), min(a[from], can)));
        a[to] += min(a[from], can);
        a[from] -= min(a[from], can);
      }
      from = to;
      to = fa[to];
    }
  }
  for (auto it : order) assert(a[it] <= v);
  reverse(order.begin(), order.end());
  for (int i = 1; i <= n; ++i) {
    bool ok = 0;
    for (auto it : order) {
      if (updated[it]) continue;
      if (a[it] >= b[it])
        ;
      else {
        ok = 1;
        int needs = b[it] - a[it];
        vector<int> way;
        int to = fa[it];
        while (to) {
          way.push_back(to);
          if (a[to] >= needs) {
            break;
          }
          to = fa[to];
        }
        reverse(way.begin(), way.end());
        way.push_back(it);
        for (int i = 0; i < way.size() - 1; ++i) {
          int move = min(a[way[i]], v - a[way[i + 1]]);
          move = min(move, needs);
          a[way[i]] -= move;
          a[way[i + 1]] += move;
          tubes.push_back(make_pair(make_pair(way[i], way[i + 1]), move));
        }
        updated[it] = 1;
        pull_up(root);
        break;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> v >> e;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i];
  for (int i = 1; i <= e; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      A = B = 0;
      dfs(i);
      if (A != B) {
        cout << "NO\n";
        return 0;
      }
      work(i);
    }
  }
  cout << tubes.size() << endl;
  for (auto it : tubes) {
    cout << it.first.first << ' ' << it.first.second << ' ' << it.second
         << endl;
  }
  return 0;
}
