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 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;
}