#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];   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;             }         }     }     for (long long x = (0); x <= (nMask); ++x)       for (long long r = (1); r <= (n); ++r)         if (!(x & id[r])) {           ok5[x][r] = 1;           for (long long i = (1); i <= (n); ++i)             if (ok5[x][r])               if (x & id[i])                 for (long long j = (1); j <= (n); ++j)                   if (x & id[j])                     if (i != j)                       if (isLCA[r][i][j]) {                         ok5[x][r] = 0;                         break;                       }         }   }   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] && ok5[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) isLCA[r][u][v] = isLCA[r][v][u] = 1;     }     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;   }