Problem: Rooted tree is a connected graph without any simple cycles with one vertex selected as a root. In this problem the vertex number 1 will always serve as a root.

Lowest common ancestor of two vertices u and v is the farthest from the root vertex that lies on both the path from u to the root and on path from v to the root. We will denote it as LCA(u, v).

Sandy had a rooted tree consisting of n vertices that she used to store her nuts. Unfortunately, the underwater storm broke her tree and she doesn't remember all it's edges. She only managed to restore m edges of the initial tree and q triples ai, bi and ci, for which she supposes LCA(ai, bi) = ci.

Help Sandy count the number of trees of size n with vertex 1 as a root, that match all the information she remembered. If she made a mess and there are no such trees then print 0. Two rooted trees are considered to be distinct if there exists an edge that occur in one of them and doesn't occur in the other one.

Input

The first line of the input contains three integers n, m and q (1 ≤ n ≤ 13, 0 ≤ m < n, 0 ≤ q ≤ 100) — the number of vertices, the number of edges and LCA triples remembered by Sandy respectively.

Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of vertices connected by the i-th edge. It's guaranteed that this set of edges is a subset of edges of some tree.

The last q lines contain the triplets of numbers ai, bi, ci (1 ≤ ai, bi, ci ≤ n). Each of these triples define LCA(ai, bi) = ci. It's not guaranteed that there exists a tree that satisfy all the given LCA conditions.

Output

Print a single integer — the number of trees of size n that satisfy all the conditions.

Examples

Input

4 0 0


Output

16


Input

4 0 1
3 4 2


Output

1


Input

3 1 0
1 2


Output

2


Input

3 0 2
2 3 2
2 3 1


Output

0


Input

4 1 2
1 2
2 2 2
3 4 2


Output

1

Note

In the second sample correct answer looks like this:

<image>

In the third sample there are two possible trees:

<image> <image>

In the fourth sample the answer is 0 because the information about LCA is inconsistent.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
void imp() {
  cout << 0 << endl;
  exit(0);
}
int n, m, q;
int LCA[20][20];
vector<pair<int, int> > E;
bool mat[20][20];
int mat2[20];
int Count[20][20];
int Bio[20];
int CheckDFS(int id, int p) {
  if (Bio[id] == 1) imp();
  if (Bio[id] == 2) return Count[id][p];
  Bio[id] = 1;
  int &r = Count[id][p];
  for (int i = (int)(0); i < (int)(n); ++i)
    if (mat[id][i] && i != p) r += CheckDFS(i, id);
  Bio[id] = 2;
  return r;
}
map<pair<int, int>, int> M;
unordered_map<int, int> M2;
int Has[20];
const int None = -1;
int LOW[1 << 13];
int low(int bit) {
  if (bit == 0) return -1;
  int cnt = 0;
  while (bit % 2 == 0) ++cnt, bit >>= 1;
  return cnt;
}
bitset<20> CANT[1 << 13];
long long dp(int id, int bit, bool ch = true) {
  static long long memo[20][1 << 13][2];
  static bool bio[20][1 << 13][2];
  long long &R = memo[id][bit][ch];
  if (bio[id][bit][ch]++) return R;
  R = 0;
  if (M2.count(bit))
    if (M2[bit] != id) return R = 0;
  if (ch)
    if ((Has[id] & bit) != Has[id]) return R = 0;
  if (CANT[bit][id]) return R = 0;
  if (bit == 0) return R = 1;
  int bit2 = (bit & mat2[id]);
  if (!bit2) {
    bit2 = bit;
    int t = LOW[bit];
    do {
      if ((bit2 >> t) & 1) {
        if (M.count({bit, bit2})) {
          int bl = M[{bit, bit2}];
          if (bl != None && ((bit2 >> bl) & 1))
            R += dp(bl, bit2 ^ (1 << bl)) * dp(id, bit ^ bit2, false);
        } else
          for (int i = (int)(0); i < (int)(n); ++i)
            if ((bit2 >> i) & 1) {
              R += dp(i, bit2 ^ (1 << i)) * dp(id, bit ^ bit2, false);
            }
      }
      bit2 = (bit & (bit2 - 1));
    } while (bit2 != bit);
    return R;
  }
  int t = (1 << LOW[bit2]);
  int bit3 = bit;
  do {
    if ((bit2 & bit3) == t)
      if (!M.count({bit, bit3}) || M[{bit, bit3}] == LOW[bit2]) {
        R += dp(LOW[bit2], bit3 ^ t) * dp(id, bit ^ bit3, false);
      }
    bit3 = (bit & (bit3 - 1));
  } while (bit3 != bit);
  return R;
}
void AddEdge(int u, int v) {
  for (int bit = (int)(0); bit < (int)(1 << n); ++bit) {
    int bit2 = bit;
    do {
      if (((bit >> u) & 1) && ((bit >> v) & 1))
        if (((bit2 >> u) & 1) && !((bit2 >> v) & 1)) {
          if (!M.count({bit, bit2})) M[{bit, bit2}] = v;
          if (M[{bit, bit2}] != v) M[{bit, bit2}] = None;
        }
      bit2 = (bit & (bit2 - 1));
    } while (bit2 != bit);
  }
}
void AddLCA(int a, int b, int c) {
  if (a == b && a != c) imp();
  if (a == b) return;
  if (c != a) Has[c] |= (1 << a);
  if (c != b) Has[c] |= (1 << b);
  for (int bit = (int)(0); bit < (int)(1 << n); ++bit) {
    if (((bit >> a) & 1) && ((bit >> b) & 1) && !((bit >> c) & 1)) {
      if (!M2.count(bit)) M2[bit] = c;
      if (M2[bit] != c) M2[bit] = None;
    }
    if (((bit >> a) & 1) && !((bit >> b) & 1)) {
      if (b != c) CANT[bit][b] = 1;
    }
    if (((bit >> b) & 1) && !((bit >> a) & 1)) {
      if (a != c) CANT[bit][a] = 1;
    }
  }
}
int main() {
  memset(LCA, -1, sizeof LCA);
  for (int i = (int)(0); i < (int)(1 << 13); ++i) LOW[i] = low(i);
  cin >> n >> m >> q;
  for (int i = (int)(0); i < (int)(m); ++i) {
    int u, v;
    cin >> u >> v, --u, --v;
    E.push_back({u, v});
    AddEdge(u, v);
    AddEdge(v, u);
    mat[u][v] = mat[v][u] = true;
    mat2[u] |= (1 << v);
    mat2[v] |= (1 << u);
  }
  for (int i = (int)(0); i < (int)(q); ++i) {
    int a, b, c;
    cin >> a >> b >> c, --a, --b, --c;
    if (LCA[a][b] != -1 && LCA[a][b] != c) imp();
    LCA[a][b] = LCA[b][a] = c;
    AddLCA(a, b, c);
  }
  for (int i = (int)(0); i < (int)(n); ++i) {
    memset(Bio, 0, sizeof Bio);
    CheckDFS(i, i);
  }
  cout << dp(0, (1 << n) - 2) << endl;
  return 0;
}