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 JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        _599E solver = new _599E();
        solver.solve(1, in, out);
        out.close();
    }

    static class _599E {
        int n;
        int m;
        int q;
        int[][] g;
        int[][] lca;
        long[][] dp;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();

            m = in.nextInt();

            q = in.nextInt();

            g = new int[n][n];

            for (int i = 0; i < m; i++) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;

                g[u][v] = 1;
                g[v][u] = 1;
            }

            lca = new int[n][n];

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    lca[i][j] = -1;
                }
            }
            for (int i = 0; i < q; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                int c = in.nextInt() - 1;

                if (a == b && c != a) {
                    out.println(0);
                    return;
                }

                if (lca[a][b] != -1 && lca[a][b] != c) {
                    out.println(0);
                    return;
                }

                lca[a][b] = c;
                lca[b][a] = c;
            }

            long ans = 0;

            dp = new long[n][1 << n];

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < (1 << n); j++) {
                    dp[i][j] = -1;
                }
            }

            ans = rec(0, (1 << n) - 1);

            out.println(ans);

        }

        long rec(int r, int mask) {

            mask &= (((1 << n) - 1) ^ (1 << r));

            if (dp[r][mask] != -1)
                return dp[r][mask];

            if ((mask & (mask - 1)) == 0) {
                if (mask != 0) {
                    int bit = Integer.numberOfTrailingZeros(mask);
                    if (lca[bit][r] != -1 && lca[bit][r] != r) {
                        return dp[r][mask] = 0;
                    }
                }
                return dp[r][mask] = 1;
            }

            long fans = 0;

//        for (int i = 0; i < n; i++) {
//            for (int j = 0; j < n; j++) {
//                if (lca[i][j] != -1) {
//                    int l = lca[i][j];
//
//                    if (((1 << l) & mask) == 0 && l != r) {
//                        return dp[r][mask] = fans;
//                    }
//                }
//            }
//        }

            int hob = Integer.highestOneBit(mask);
            for (int i = mask; i >= hob; i--) {
                i &= mask;
                long ans = 0;
                Set<Integer> s = new HashSet<>();
                int nr = -1;
                boolean isp = true;
                for (int j = 0; j < n; j++) {
                    if (((1 << j) & i) != 0) {
                        s.add(j);
                        if (g[r][j] == 1) {
                            if (nr != -1) {
                                isp = false;
                                break;
                            }
                            nr = j;
                        }
                    }
                }

                if (!isp)
                    continue;

                if (q > 0)
                    for (Integer a : s) {
                        for (Integer b : s) {
                            if (lca[a][b] == -1)
                                continue;

                            if (lca[a][b] == r || !s.contains(lca[a][b])) {
                                isp = false;
                                break;
                            }
                        }
                    }

                if (q > 0)
                    for (int a = 0; a < n; a++) {
                        if (!s.contains(a) && (((1 << a) & mask) != 0 || a == r))
                            for (Integer b : s) {
                                if (lca[a][b] != -1 && lca[a][b] != r)
                                    isp = false;
                            }
                    }

                if (m > 0)
                    for (int a = 0; a < n; a++) {
                        for (Integer b : s) {
                            if (g[b][a] == 1 && !s.contains(a) && a != r)
                                isp = false;
                        }
                    }

                if (!isp)
                    continue;

                if (nr == -1) {
                    for (Integer a : s) {
                        ans += rec(a, i) * rec(r, mask ^ i);
                    }
                } else {
                    ans += rec(nr, i) * rec(r, mask ^ i);
                }

                fans += ans;
            }

            return (dp[r][mask] = fans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}