This problem consists of two subproblems: for solving subproblem E1 you will receive 11 points, and for solving subproblem E2 you will receive 13 points.

A tree is an undirected connected graph containing no cycles. The distance between two nodes in an unweighted tree is the minimum number of edges that have to be traversed to get from one node to another.

You are given 3 trees that have to be united into a single tree by adding two edges between these trees. Each of these edges can connect any pair of nodes from two trees. After the trees are connected, the distances between all unordered pairs of nodes in the united tree should be computed. What is the maximum possible value of the sum of these distances?
The first line contains three space-separated integers *n*<sub class="lower-index">1</sub>, *n*<sub class="lower-index">2</sub>, *n*<sub class="lower-index">3</sub> — the number of vertices in the first, second, and third trees, respectively. The following *n*<sub class="lower-index">1</sub> - 1 lines describe the first tree. Each of these lines describes an edge in the first tree and contains a pair of integers separated by a single space — the numeric labels of vertices connected by the edge. The following *n*<sub class="lower-index">2</sub> - 1 lines describe the second tree in the same fashion, and the *n*<sub class="lower-index">3</sub> - 1 lines after that similarly describe the third tree. The vertices in each tree are numbered with consecutive integers starting with 1.

The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
 -  In subproblem E1 (11 points), the number of vertices in each tree will be between 1 and 1000, inclusive. -  In subproblem E2 (13 points), the number of vertices in each tree will be between 1 and 100000, inclusive.
#! /usr/bin/env python3

import sys

MAX_INT = 2**31 - 1

class Node:

    def __init__(self, num):
        self.num = num
        self.binds = []
        # for dijkstra
        self.marker = False
        self.val = None

    def add_bind(self, oth):
        self.binds.append(oth)

    def __repr__(self):
        return '<{}: {}{}>'.format(
            self.num,
            [i.num for i in self.binds],
            ', \tval: {}'.format(self.val) if self.val != None else ''
            )

def dijkstra(node):
    new_val = node.val + 1
    for neith in node.binds:
        if not neith.marker:
            neith.val = min(neith.val, new_val)
    node.marker = True
    for neith in node.binds:
        if not neith.marker:
            dijkstra(neith)

def calc_edges_muls(node, N):
    node.marker = True
    sum_dists_below = 0
    sum_nodes_below = 1
    total_dists = 0
    for neith in node.binds:
        if not neith.marker:
            nodes_below, dists_below, total_dists_below = calc_edges_muls(neith, N)
            sum_nodes_below += nodes_below
            sum_dists_below += dists_below
            total_dists += total_dists_below
            total_dists += (N - nodes_below) * nodes_below
    if sum_nodes_below == 1:
        return 1, 0, 0
    return sum_nodes_below, sum_dists_below, total_dists

class Graph:

    def __init__(self, size):
        self.size = size
        self.nodes = [None] + [Node(num) for num in range(1, size+1)]

    def read_input(self):
        for _ in range(1, self.size):
            i, j = (int(x) for x in sys.stdin.readline().split())
            self.nodes[i].add_bind(self.nodes[j])
            self.nodes[j].add_bind(self.nodes[i])

    def find_most_far(self):
        if self.size == 1:
            self.most_far_node = self.nodes[1]
            self.max_dist_sum = 0
            return
        ends = [node for node in self.nodes[1:] if len(node.binds) == 1]
        self.most_far_node = None
        self.max_dist_sum = 0
        for end in ends:
            self.drop_nodes_marker()
            self.init_nodes_val(MAX_INT)
            end.val = 0
            dijkstra(end)
            dist_sum = sum(node.val for node in self.nodes[1:])
            if dist_sum > self.max_dist_sum:
                self.max_dist_sum = dist_sum
                self.most_far_node = end

    def drop_nodes_marker(self):
        for node in self.nodes[1:]:
            node.marker = False

    def init_nodes_val(self, val):
        for node in self.nodes[1:]:
            node.val = val

    def extend(self, oth):

        offset = self.size
        for node in oth.nodes[1:]:
            node.num += offset
            self.nodes.append(node)
        self.size += oth.size

        self.most_far_node.add_bind(oth.most_far_node)
        oth.most_far_node.add_bind(self.most_far_node)

        self.most_far_node = None
        self.max_dist_sum = None

    def calc_total_sum(self):

        self.drop_nodes_marker()
        self.init_nodes_val(0)
        self.total_dist_sum = 0

        root = next(node for node in self.nodes[1:] if len(node.binds) == 1)
        a, b, c = calc_edges_muls(root, self.size)
        #print(a, b, c)
        self.total_dist_sum = c

    def __repr__(self):
        return '\n'.join(str(node) for node in self.nodes[1:])


Ns = [int(i) for i in sys.stdin.readline().split()]
GRAPHs = []
for n in Ns:
    GRAPHs.append(Graph(n))

for g in GRAPHs:
    g.read_input()

# preloop
for g in GRAPHs:
    g.find_most_far()

# 1st iter
GRAPHs.sort(key=lambda g: g.max_dist_sum)

g = GRAPHs.pop(0)
GRAPHs[0].extend(g)

# 2nd iter
GRAPHs[0].find_most_far()
GRAPHs.sort(key=lambda g: g.max_dist_sum)

g = GRAPHs.pop(0)
GRAPHs[0].extend(g)

# result
g = GRAPHs.pop()
g.calc_total_sum()
print(g.total_dist_sum)