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;
int n, v, m;
vector<int> mam, chce;
vector<int> x, y, z;
vector<int> Z;
void Stworz(int n) {
  for (int i = 0; i < n; ++i) Z.push_back(i);
}
int Find(int a) {
  if (Z[a] == a) return a;
  int fa = Find(Z[a]);
  Z[a] = fa;
  return fa;
}
void Union(int a, int b) { Z[Find(a)] = Find(b); }
void dfsOjciec(int start, vector<vector<int> >& G, vector<bool>& odw,
               vector<int>& oj) {
  stack<int> S;
  S.push(start);
  odw[start] = true;
  oj[start] = -1;
  while (!S.empty()) {
    int akt = S.top();
    S.pop();
    for (int i = 0; i < G[akt].size(); ++i) {
      if (!odw[G[akt][i]]) {
        odw[G[akt][i]] = true;
        S.push(G[akt][i]);
        oj[G[akt][i]] = akt;
      }
    }
  }
}
void P(int a, int b, int c) {
  x.push_back(a);
  y.push_back(b);
  z.push_back(c);
  mam[a] -= c;
  mam[b] += c;
}
void dfsWGore(int start, vector<vector<int> >& G, vector<bool>& odw,
              vector<int>& oj) {
  stack<int> S;
  S.push(start);
  odw[start] = true;
  while (!S.empty()) {
    int akt = S.top();
    S.pop();
    int t = akt;
    while (oj[t] != -1 && mam[oj[t]] == 0) {
      P(t, oj[t], mam[t]);
      t = oj[t];
    }
    if (oj[t] != -1) P(t, oj[t], min(v - mam[oj[t]], mam[t]));
    for (int i = 0; i < G[akt].size(); ++i) {
      if (!odw[G[akt][i]]) {
        odw[G[akt][i]] = true;
        S.push(G[akt][i]);
      }
    }
  }
}
void Napraw(vector<vector<int> >& G, vector<int>& oj, vector<bool>& jest,
            int akt) {
  while (true) {
    int nast = -1;
    for (int i = 0; i < G[akt].size(); ++i)
      if (G[akt][i] != oj[akt] && mam[G[akt][i]] == v && !jest[G[akt][i]])
        nast = G[akt][i];
    if (nast != -1) {
      P(nast, akt, v - mam[akt]);
      akt = nast;
    } else {
      for (int i = 0; i < G[akt].size(); ++i)
        if (G[akt][i] != oj[akt] && mam[akt] < v && !jest[G[akt][i]])
          P(G[akt][i], akt, min(v - mam[akt], mam[G[akt][i]]));
      break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> v >> m;
  for (int i = 0; i < n; ++i) {
    int m;
    cin >> m;
    mam.push_back(m);
  }
  for (int i = 0; i < n; ++i) {
    int c;
    cin >> c;
    chce.push_back(c);
  }
  Stworz(n);
  vector<vector<int> > G(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    if (Find(x) != Find(y)) {
      G[x].push_back(y);
      G[y].push_back(x);
      Union(x, y);
    }
  }
  long long mamS, chceS;
  for (int i = 0; i < n; ++i) {
    mamS = chceS = 0;
    for (int j = 0; j < n; ++j) {
      if (Find(i) == Find(j)) {
        mamS += mam[j];
        chceS += chce[j];
      }
    }
    if (mamS != chceS) {
      cout << "NO";
      return 0;
    }
  }
  vector<int> oj(n);
  vector<bool> odw(n, false);
  for (int i = 0; i < n; ++i)
    if (!odw[i]) dfsOjciec(i, G, odw, oj);
  for (int i = 0; i < n; ++i) odw[i] = false;
  for (int i = 0; i < n; ++i)
    if (!odw[i]) dfsWGore(i, G, odw, oj);
  vector<bool> jest(n, false);
  while (true) {
    vector<int> moge;
    for (int i = 0; i < n; ++i) {
      if (jest[i]) continue;
      bool ok = true;
      for (int j = 0; j < G[i].size(); ++j)
        if (G[i][j] != oj[i] && !jest[G[i][j]]) ok = false;
      if (ok) moge.push_back(i);
    }
    if (moge.size() == 0) break;
    for (int i = 0; i < moge.size(); ++i)
      if (mam[moge[i]] == chce[moge[i]]) jest[moge[i]] = true;
    int akt = -1;
    for (int i = 0; i < moge.size(); ++i)
      if (mam[moge[i]] < chce[moge[i]]) akt = moge[i];
    if (akt == -1) continue;
    int potrze = chce[akt] - mam[akt];
    vector<int> path;
    path.push_back(akt);
    int t = oj[akt];
    while (mam[t] == 0) {
      path.push_back(t);
      t = oj[t];
    }
    path.push_back(t);
    reverse(path.begin(), path.end());
    int napr = -1;
    if (mam[t] == v) napr = t;
    if (mam[t] < potrze) {
      napr = oj[t];
      P(oj[t], t, potrze - mam[t]);
    }
    for (int i = 1; i < path.size(); ++i) P(path[i - 1], path[i], potrze);
    jest[akt] = true;
    if (napr != -1) Napraw(G, oj, jest, napr);
  }
  cout << x.size() << endl;
  for (int i = 0; i < x.size(); ++i)
    cout << x[i] + 1 << " " << y[i] + 1 << " " << z[i] << endl;
  return 0;
}