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 <class T>
inline T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
template <class T>
void read(T &x) {
  char ch;
  while ((ch = getchar()) && !isdigit(ch))
    ;
  x = ch - '0';
  while ((ch = getchar()) && isdigit(ch)) x = x * 10 + ch - '0';
}
struct point {
  int x, y;
  point() {}
  point(int _x, int _y) : x(_x), y(_y) {}
};
struct flow {
  int x, y, c;
  flow() {}
  flow(int _x, int _y, int _c) : x(_x), y(_y), c(_c) {}
};
const int N = 400;
vector<int> E[N];
long long sum;
int a[N], b[N], fa[N], n, v, m, vis[N], al;
long long Left[N], all[N];
vector<flow> Ans;
void dfs_check(int w, int Fa) {
  sum += (long long)(b[w] - a[w]);
  for (int i = 0; i < E[w].size(); i++)
    if (E[w][i] != Fa) dfs_check(E[w][i], w);
}
int g_f(int x) { return fa[x] == x ? x : fa[x] = g_f(fa[x]); }
void dfs_all(int w, int Fa) {
  all[w] = v - a[w];
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      dfs_all(E[w][i], w);
      all[w] += all[E[w][i]];
    }
}
void dfs_Left(int w, int Fa) {
  Left[w] = a[w];
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      dfs_Left(E[w][i], w);
      Left[w] += Left[E[w][i]];
    }
}
void push(int w, int c, int Fa) {
  if (v - a[w] >= c) {
    Ans.push_back(flow(Fa, w, c));
    a[Fa] -= c;
    a[w] += c;
    return;
  }
  int now = c, T = c - (v - a[w]);
  if (a[w] != v)
    Ans.push_back(flow(Fa, w, v - a[w])), a[Fa] -= v - a[w], a[w] = v;
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      int can = min(all[E[w][i]], (long long)now);
      push(E[w][i], can, w);
      now -= can;
      if (!now) break;
    }
  Ans.push_back(flow(Fa, w, T));
  a[Fa] -= T;
  a[w] += T;
}
void pull(int w, int c, int Fa) {
  if (a[w] >= c) {
    Ans.push_back(flow(w, Fa, c));
    a[Fa] += c;
    a[w] -= c;
    return;
  }
  int now = c, T = c - a[w];
  if (a[w]) Ans.push_back(flow(w, Fa, a[w])), a[Fa] += a[w], a[w] = 0;
  for (int i = 0; i < E[w].size(); i++)
    if (!vis[E[w][i]] && E[w][i] != Fa) {
      int can = min(Left[E[w][i]], (long long)now);
      pull(E[w][i], can, w);
      now -= can;
      if (!now) break;
    }
  Ans.push_back(flow(w, Fa, T));
  a[Fa] += T;
  a[w] -= T;
}
void work(int x) {
  if (a[x] == b[x])
    return;
  else if (a[x] > b[x]) {
    dfs_all(x, 0);
    int now = a[x] - b[x];
    for (int i = 0; i < E[x].size(); i++)
      if (!vis[E[x][i]]) {
        int c = min(all[E[x][i]], (long long)now);
        push(E[x][i], c, x);
        now -= c;
        if (!now) break;
      }
  } else if (a[x] < b[x]) {
    dfs_Left(x, 0);
    int now = b[x] - a[x];
    for (int i = 0; i < E[x].size(); i++)
      if (!vis[E[x][i]]) {
        int c = min(Left[E[x][i]], (long long)now);
        pull(E[x][i], c, x);
        now -= c;
        if (!now) break;
      }
  }
}
int rd[N];
queue<int> Q;
int main() {
  scanf("%d%d%d", &n, &v, &m);
  int x, y;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (g_f(x) != g_f(y))
      fa[g_f(x)] = g_f(y), E[x].push_back(y), E[y].push_back(x), rd[x]++,
      rd[y]++;
  }
  for (int i = 1; i <= n; i++) {
    dfs_check(i, 0);
    if (sum != 0) {
      puts("NO");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    if (rd[i] == 1) Q.push(i);
  while (Q.size()) {
    int x = Q.front();
    vis[x] = 1;
    work(x);
    Q.pop();
    for (int i = 0; i < E[x].size(); i++) {
      rd[E[x][i]]--;
      if (rd[E[x][i]] == 1) Q.push(E[x][i]);
    }
  }
  printf("%d\n", Ans.size());
  for (int i = 0; i < Ans.size(); i++)
    printf("%d %d %d\n", Ans[i].x, Ans[i].y, Ans[i].c);
}