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;
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v);
const int N = 340;
bool color[N];
vector<int> adj[N];
int n;
int cap;
int parent[N];
int has[N];
int desired[N];
int deg[N];
bool solved[N];
long long dfs(int v) {
  if (!color[v]) return 0;
  color[v] = false;
  long long res = has[v] - desired[v];
  for (__typeof((adj[v]).begin()) u = (adj[v]).begin(); u != (adj[v]).end();
       u++) {
    if (color[*u]) {
      parent[*u] = v;
      deg[v]++;
      res += dfs(*u);
    }
  }
  return res;
}
bool check() {
  for (int i = 0; i < (n); i++) {
    parent[i] = -1;
    color[i] = true;
    deg[i] = 0;
  }
  for (int i = 0; i < (n); i++) {
    long long x = dfs(i);
    if (x != 0) return false;
  }
  return true;
}
struct tr {
  int a, b, c;
  tr(int x, int y, int z) {
    a = x;
    b = y;
    c = z;
  }
};
vector<tr> ans;
void send(int a, int b, int k) {
  if (k == 0) return;
  ans.push_back(tr(a + 1, b + 1, k));
  has[a] -= k;
  has[b] += k;
}
void out(int v, int cnt) {
  if (color[v] == false) return;
  color[v] = false;
  cnt = min(cnt, has[v]);
  for (__typeof((adj[v]).begin()) u = (adj[v]).begin(); u != (adj[v]).end();
       u++) {
    if (color[*u] == false) continue;
    out(*u, cnt);
    int tmp = min(cap - has[*u], cnt);
    send(v, *u, tmp);
    cnt -= tmp;
  }
}
void outward(int v, int cnt) {
  for (int i = 0; i < (n); i++) color[i] = !solved[i];
  out(v, cnt);
}
void in(int v, int cnt) {
  if (color[v] == 0) return;
  color[v] = false;
  cnt = min(cnt, cap - has[v]);
  for (__typeof((adj[v]).begin()) u = (adj[v]).begin(); u != (adj[v]).end();
       u++) {
    if (color[*u] == false) continue;
    in(*u, cnt);
    int tmp = min(has[*u], cnt);
    send(*u, v, tmp);
    cnt -= tmp;
  }
}
void inward(int v, int cnt) {
  for (int i = 0; i < (n); i++) color[i] = !solved[i];
  in(v, cnt);
}
void solve(int v) {
  if (has[v] > desired[v]) {
    outward(v, has[v] - desired[v]);
  } else {
    inward(v, desired[v] - has[v]);
  }
  solved[v] = true;
}
int main() {
  int m;
  scanf("%d %d %d", &n, &cap, &m);
  for (int i = 0; i < (n); i++) scanf("%d", &has[i]);
  for (int i = 0; i < (n); i++) scanf("%d", &desired[i]);
  for (int i = 0; i < (m); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if (!check()) {
    printf("NO\n");
    return 0;
  }
  for (int i = 0; i < (n); i++) solved[i] = false;
  queue<int> q;
  for (int i = 0; i < (n); i++) {
    if (deg[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    solve(v);
    if (parent[v] != -1) {
      if ((--deg[parent[v]]) == 0) {
        q.push(parent[v]);
      }
    }
  }
  printf("%d\n", ans.size());
  for (__typeof((ans).begin()) t = (ans).begin(); t != (ans).end(); t++) {
    printf("%d %d %d\n", t->a, t->b, t->c);
  }
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  bool first = true;
  for (__typeof((v).begin()) x = (v).begin(); x != (v).end(); x++) {
    if (!first) {
      o << ", ";
    }
    o << *x;
    first = false;
  }
  o << "]";
  return o;
}