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;
inline long long read() {
  long long x;
  cin >> x;
  return x;
}
const int MAX_N = 15;
const int MAX_F = (1 << (MAX_N - 2)) + 4;
int n, m, nQ, id[MAX_N];
bool isEdge[MAX_N][MAX_N], isParent[MAX_N][MAX_N], isNotParent[MAX_N][MAX_N],
    isLCA[MAX_N][MAX_N][MAX_N];
bool ok1[MAX_F][MAX_N], ok2[MAX_F][MAX_N], ok3[MAX_F][MAX_N][MAX_N],
    ok4[MAX_F][MAX_F], ok5[MAX_F][MAX_N];
long long f[MAX_F][MAX_N];
vector<pair<int, int> > lca[MAX_N];
inline bool check_0(int u, int v, int r) {
  if (u == v && r != u) return 0;
  if ((u == 1 || v == 1) && r != 1) return 0;
  return 1;
}
void init(int nMask) {
  memset(ok1, 0, sizeof(ok1));
  memset(ok2, 0, sizeof(ok2));
  memset(ok3, 0, sizeof(ok3));
  memset(ok4, 0, sizeof(ok4));
  memset(ok5, 0, sizeof(ok5));
  for (long long x = (0); x <= (nMask); ++x)
    for (long long i = (1); i <= (n); ++i)
      if (x & id[i]) {
        ok1[x][i] = 1;
        for (long long j = (1); j <= (n); ++j)
          if (j != i && (x & id[j]))
            if (isParent[j][i] || isNotParent[i][j]) {
              ok1[x][i] = 0;
              break;
            }
      }
  for (long long x = (0); x <= (nMask); ++x)
    for (long long i = (1); i <= (n); ++i)
      if (!(x & id[i])) {
        ok2[x][i] = 1;
        for (long long j = (1); j <= (n); ++j)
          if (x & id[j])
            if (isParent[j][i] || isParent[i][j] || isEdge[j][i] ||
                isEdge[i][j]) {
              ok2[x][i] = 0;
              break;
            }
      }
  for (long long x = (0); x <= (nMask); ++x)
    for (long long i = (1); i <= (n); ++i)
      if (x & id[i])
        for (long long r = (1); r <= (n); ++r)
          if (!(x & id[r])) {
            ok3[x][i][r] = 1;
            for (long long j = (1); j <= (n); ++j)
              if (j != i && (x & id[j]))
                if (isEdge[r][j]) {
                  ok3[x][i][r] = 0;
                  break;
                }
          }
  for (long long x = (0); x <= (nMask); ++x) {
    for (long long y = (0); y <= (nMask); ++y)
      if (!(x & y)) {
        ok4[x][y] = 1;
        for (long long i = (1); i <= (n); ++i)
          if (x & id[i]) {
            for (long long j = (1); j <= (n); ++j)
              if (y & id[j])
                if (isParent[i][j] || isParent[j][i] || isEdge[i][j] ||
                    isEdge[j][i]) {
                  ok4[x][y] = 0;
                  break;
                }
            if (!ok4[x][y]) break;
          }
      }
  }
}
inline bool checkLCA(int mask, int r) {
  for (__typeof(lca[r].begin()) it = lca[r].begin(); it != lca[r].end(); it++)
    if ((mask & id[it->first]) && (mask & id[it->second])) return 0;
  return 1;
}
inline bool check(int mask, int r, int newMask, int newR) {
  int x = mask - newMask;
  return ok1[newMask][newR] && ok2[x][newR] && ok3[newMask][newR][r] &&
         ok4[newMask][x] && checkLCA(newMask, r);
}
long long solve(int mask, int par) {
  if (mask == 0) return 1;
  if (f[mask][par] > -1) return f[mask][par];
  long long ans = 0;
  int x = 0;
  do {
    if (x > 0 && __builtin_clz(x) == __builtin_clz(mask))
      for (long long r = (1); r <= (n); ++r)
        if (x & id[r]) {
          if (!check(mask, par, x, r)) continue;
          long long t = solve(x - id[r], r) * solve(mask - x, par);
          ans += t;
        }
    x = (x + 1 + (~mask)) & mask;
  } while (x);
  return f[mask][par] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(9);
  cout.setf(ios::fixed, ios::floatfield);
  memset(isEdge, 0, sizeof(isEdge));
  memset(isParent, 0, sizeof(isParent));
  memset(isNotParent, 0, sizeof(isNotParent));
  memset(isLCA, 0, sizeof(isLCA));
  cin >> n >> m >> nQ;
  for (long long i = (1); i <= (n); ++i) id[i] = 1 << (i - 1);
  while (m--) {
    int u, v;
    cin >> u >> v;
    isEdge[u][v] = isEdge[v][u] = 1;
  }
  while (nQ--) {
    int u, v, r;
    cin >> u >> v >> r;
    if (!check_0(u, v, r)) {
      cout << 0 << '\n';
      return 0;
    }
    if (r != u) isNotParent[u][v] = 1;
    if (r != v) isNotParent[v][u] = 1;
    isParent[r][u] = isParent[r][v] = 1;
    if (r != u && r != v) {
      lca[r].push_back(make_pair(u, v));
    }
  }
  for (long long i = (1); i <= (n); ++i) isParent[i][i] = isNotParent[i][i] = 0;
  memset(f, -1, sizeof(f));
  int mask = 0;
  for (long long i = (2); i <= (n); ++i) mask |= id[i];
  init(mask);
  cout << solve(mask, 1) << '\n';
  return 0;
}