Problem: A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tubes equals e. Volume of each vessel equals v liters. Of course, the amount of the water in any vessel cannot exceed v liters in the process of transfusions.

Given the initial amounts ai of water in the vessels and the desired amounts bi find a sequence of transfusions that deals with the task. Total number of transfusions must not exceed 2·n2.

Input

First line of the input contains integers n, v, e (1 ≤ n ≤ 300, 1 ≤ v ≤ 109, 0 ≤ e ≤ 50000).

Next two lines contain n integers each: initial ai and the desired amounts bi of water in corresponding vessels (0 ≤ ai, bi ≤ v).

Next e lines describe one tube each in the format x y (1 ≤ x, y ≤ n, x ≠ y) for a tube between vessels number x and y. There might be multiple tubes between two vessels. You may assume that vessels are numbered from 1 to n in some way.

Output

Print "NO" (without quotes), if such sequence of transfusions does not exist.

Otherwise print any suitable sequence in the following format. On the first line print the total number of transfusions k (k should not exceed 2·n2). In the following k lines print transfusions in the format x y d (transfusion of d liters from the vessel number x to the vessel number y, x and y must be distinct). For all transfusions d must be a non-negative integer.

Examples

Input

2 10 1
1 9
5 5
1 2


Output

1
2 1 4


Input

2 10 0
5 2
4 2


Output

NO


Input

2 10 0
4 2
4 2


Output

0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
template <class T>
inline T isqrt(T k) {
  T r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
template <class T>
inline T icbrt(T k) {
  T r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const int maxn = 300 + 5;
int n, V, m;
int a[maxn];
int b[maxn];
int need[maxn];
template <class T, T oo>
struct MaximumFlow {
  static const int MAXV = 100000 + 5;
  static const int MAXE = 1000000 + 5;
  int n, s, t, E;
  int adj[MAXE], nxt[MAXE], lst[MAXV], run[MAXV], lev[MAXV], frm[MAXV],
      que[MAXV];
  T flw[MAXE], cap[MAXE];
  void init(int n, int s, int t) {
    this->n = n, this->s = s, this->t = t, E = 0;
    fill_n(lst, n + 1, -1);
  }
  void add(int u, int v, T c1, T c2) {
    adj[E] = v, flw[E] = 0, cap[E] = c1, nxt[E] = lst[u], lst[u] = E++;
    adj[E] = u, flw[E] = 0, cap[E] = c2, nxt[E] = lst[v], lst[v] = E++;
  }
  int bfs() {
    fill_n(lev, n + 1, -1);
    lev[s] = 0;
    int qsize = 0;
    que[qsize++] = s;
    for (int i = 0; i < qsize; i++) {
      for (int u = que[i], e = lst[u]; ~e; e = nxt[e]) {
        int v = adj[e];
        if (flw[e] < cap[e] && !~lev[v]) {
          lev[v] = lev[u] + 1;
          que[qsize++] = v;
        }
      }
    }
    return lev[t] != -1;
  }
  T dfs(int u, T bot) {
    if (u == t) return bot;
    for (int& e = run[u]; ~e; e = nxt[e]) {
      int v = adj[e];
      T delta = 0;
      if (lev[v] == lev[u] + 1 && flw[e] < cap[e] &&
          (delta = dfs(v, min(bot, cap[e] - flw[e]))) > 0) {
        flw[e] += delta;
        flw[e ^ 1] -= delta;
        frm[v] = e;
        return delta;
      }
    }
    return 0;
  }
  vector<pair<pair<int, int>, int> > res;
  T maxflow() {
    T total = 0;
    while (bfs()) {
      for (int i = 0; i <= n; i++) run[i] = lst[i];
      for (T delta = dfs(s, V); delta > 0; delta = dfs(s, V)) {
        total += delta;
        vector<int> path;
        int cur = t;
        while (cur != s) {
          if (cur != t) {
            path.push_back(cur);
          }
          int e = frm[cur];
          cur = adj[e ^ 1];
        }
        for (int i = (0); i < (int((path).size()) - 1); i++) {
          int u = path[i];
          need[u] = delta;
        }
        while (1) {
          int found = 0;
          for (int i = (0); i < (int((path).size()) - 1); i++) {
            int u = path[i];
            int v = path[i + 1];
            if (need[u]) {
              found = 1;
              int x = min(V - a[u], need[u]);
              if (a[v] >= x) {
                res.push_back(make_pair(make_pair(v, u), x));
                need[u] -= x;
                a[u] += x;
                a[v] -= x;
              } else if (a[v]) {
                res.push_back(make_pair(make_pair(v, u), a[v]));
                need[u] -= a[v];
                a[u] += a[v];
                a[v] = 0;
              }
            }
          }
          if (!found) break;
        }
      }
    }
    return total;
  }
};
MaximumFlow<long long, (long long)1e18> mf;
void solve() {
  cin >> n >> V >> m;
  long long dif = 0, sum = 0;
  for (int i = (0); i < (n); i++) cin >> a[i], dif += a[i], sum += a[i];
  for (int i = (0); i < (n); i++) cin >> b[i], dif -= b[i];
  if (dif) {
    cout << "NO\n";
    return;
  }
  int tot = n, s = tot++, t = tot++;
  mf.init(tot, s, t);
  for (int i = (0); i < (m); i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    mf.add(u, v, LINF, 0);
    mf.add(v, u, LINF, 0);
  }
  for (int i = (0); i < (n); i++) {
    mf.add(s, i, a[i], 0);
    mf.add(i, t, b[i], 0);
  }
  if (mf.maxflow() != sum) {
    cout << "NO\n";
    return;
  }
  cout << int((mf.res).size()) << "\n";
  for (int i = (0); i < (int((mf.res).size())); i++) {
    cout << mf.res[i].first.first + 1 << " " << mf.res[i].first.second + 1
         << " " << mf.res[i].second << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}