You are given $3$ unweighted, undirected graphs, $G_1$, $G_2$, and $G_3$, with $n$ vertices each, where the $k^{th}$ graph has $m_{k}$ edges and the vertices in each graph are numbered from $\mbox{1}$ through $n$. Find the number of ordered triples $(a,b,c)$, where $1\leq a,b,c\leq n$, $a\neq b,b\neq c,c\neq a$, such that there is an edge $(a,b)$ in $G_1$, an edge $(b,c)$ in $G_2$, and an edge $(c,a)$ in $G_3$.

Input Format

The first line contains single integer, $n$, denoting the number of vertices in the graphs. The subsequent lines define $G_1$, $G_2$, and $G_3$. Each graph is defined as follows:

The first line contains an integer, $m$, describing the number of edges in the graph being defined.
Each line $\boldsymbol{i}$ of the $m$ subsequent lines (where $1\leq i\leq m$) contains $2$ space-separated integers describing the respective nodes, $u_i$ and $v_i$ connected by edge $\boldsymbol{i}$.

Constraints

$n\leq10^{5}$
$m_k\leq10^5$, and $k\in\{1,2,3\}$
Each graph contains no cycles and any pair of directly connected nodes is connected by a maximum of $\mbox{1}$ edge.

Output Format

Print a single integer denoting the number of distinct $(a,b,c)$ triples as described in the Problem Statement above.

Sample Input
3
2
1 2
2 3
3
1 2
1 3
2 3
2
1 3
2 3

Sample Output
3

Explanation

There are three possible triples in our Sample Input: 

$(1,2,3)$
$(2,1,3)$
$(3,2,1)$

Thus, we print $3$ as our output.

Difficulty: MEDIUM_HARD

Solutions:
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


class graph:

	def __init__(self, n):
		self.bitset = set()
		self.nums = {}
		self.n = n

	def __add__(self, other):
		(a, b) = other
		(a, b) = (a - 1, b - 1)
		self.bitset.add(a + b * self.n)
		self.bitset.add(b + a * self.n)
		self.add_num(a, b)
		self.add_num(b, a)
		return self

	def add_num(self, a, b):
		if a in self.nums:
			self.nums[a].add(b)
		else:
			self.nums[a] = {b}

	def __contains__(self, val):
		(a, b) = val
		return a + b * self.n in self.bitset
n = int(input())
gs = []
for i in range(3):
	m = int(input())
	gi = graph(n)
	gs.append(gi)
	for i in range(m):
		e = map(int, input().strip().split(' '))
		gi += e
count = 0
for (a, bs) in gs[0].nums.items():
	for b in bs:
		valid = False
		if a in gs[1].nums:
			if b in gs[2].nums:
				count += len(gs[1].nums[a].intersection(gs[2].nums[b]))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import sys

def main():
	N = int(sys.stdin.readline())
	M = []
	G = []
	for i in range(3):
		M.append(int(sys.stdin.readline()))
		G.append([set() for _ in range(N)])
		for _ in range(M[i]):
			(u, v) = map(int, sys.stdin.readline().split())
			(u, v) = (u - 1, v - 1)
			G[i][u].add(v)
			G[i][v].add(u)
	cpt = 0
	for a in range(N):
		for b in G[0][a]:
			for c in G[1][b]:
				if a in G[2][c]:
					cpt += 1
	print(cpt)
main()


import sys

def main():
	N = int(sys.stdin.readline())
	M = []
	G = []
	for i in range(3):
		M.append(int(sys.stdin.readline()))
		G.append([set() for _ in range(N)])
		for _ in range(M[i]):
			(u, v) = map(int, sys.stdin.readline().split())
			(u, v) = (u - 1, v - 1)
			G[i][u].add(v)
			G[i][v].add(u)
	cpt = 0
	for a in range(N):
		for b in G[0][a]:
			for c in G[1][b]:
				if a in G[2][c]:
					cpt += 1
	print(cpt)
main()


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import sys

def main():
	N = int(sys.stdin.readline())
	M = []
	G = []
	for i in range(3):
		M.append(int(sys.stdin.readline()))
		G.append([set() for _ in range(N)])
		for _ in range(M[i]):
			(u, v) = map(int, sys.stdin.readline().split())
			(u, v) = (u - 1, v - 1)
			G[i][u].add(v)
			G[i][v].add(u)
	cpt = 0
	for a in range(N):
		for b in G[0][a]:
			for c in G[1][b]:
				if a in G[2][c]:
					cpt += 1
	print(cpt)
main()


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import sys

def main():
	N = int(sys.stdin.readline())
	M = []
	G = []
	for i in range(3):
		M.append(int(sys.stdin.readline()))
		G.append([set() for _ in range(N)])
		for _ in range(M[i]):
			(u, v) = map(int, sys.stdin.readline().split())
			(u, v) = (u - 1, v - 1)
			G[i][u].add(v)
			G[i][v].add(u)
	cpt = 0
	for a in range(N):
		for b in G[0][a]:
			for c in G[1][b]:
				if a in G[2][c]:
					cpt += 1
	print(cpt)
main()


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import math
import os
import random
import re
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
komalika = int(input())
chi = [[], [], [], []]
vinni = 0
W1 = 1
W2 = 2
W3 = 3
for t in range(1, 4):
	for o in range(0, komalika + 1):
		chi[t].append(None)
for t in range(1, 4):
	ert = int(input())
	for j in range(0, ert):
		ert = list(map(int, input().split(' ')))
		if chi[t][ert[0]] is None:
			chi[t][ert[0]] = set()
		chi[t][ert[0]].add(ert[1])
		if chi[t][ert[1]] is None:
			chi[t][ert[1]] = set()
		chi[t][ert[1]].add(ert[0])
for komal in range(1, komalika + 1):
	komalToW1 = chi[W1][komal]
	if komalToW1 is not None:
		komalFromW2 = chi[W2][komal]
		if komalFromW2 is not None:
			for tokomal in komalFromW2:
				komalFromW3 = chi[W3][tokomal]
				if komalFromW3 is not None:
					vinni = vinni + len(komalToW1.intersection(komalFromW3))
print(vinni)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for rolex in range(1, vertices + 1):
	verticesToG1 = graph[G1][rolex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][rolex]
		if verticesFromG2 is not None:
			for torolex in verticesFromG2:
				verticesFromG3 = graph[G3][torolex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import sys

def main():
	N = int(sys.stdin.readline())
	M = []
	G = []
	for i in range(3):
		M.append(int(sys.stdin.readline()))
		G.append([set() for _ in range(N)])
		for _ in range(M[i]):
			(u, v) = map(int, sys.stdin.readline().split())
			(u, v) = (u - 1, v - 1)
			G[i][u].add(v)
			G[i][v].add(u)
	cpt = 0
	for a in range(N):
		for b in G[0][a]:
			for c in G[1][b]:
				if a in G[2][c]:
					cpt += 1
	print(cpt)
main()


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)


import os
import sys
vertices = int(input())
graph = [[], [], [], []]
count = 0
G1 = 1
G2 = 2
G3 = 3
for i in range(1, 4):
	for j in range(0, vertices + 1):
		graph[i].append(None)
for i in range(1, 4):
	edges = int(input())
	for j in range(0, edges):
		edge = list(map(int, input().split(' ')))
		if graph[i][edge[0]] is None:
			graph[i][edge[0]] = set()
		graph[i][edge[0]].add(edge[1])
		if graph[i][edge[1]] is None:
			graph[i][edge[1]] = set()
		graph[i][edge[1]].add(edge[0])
for vertex in range(1, vertices + 1):
	verticesToG1 = graph[G1][vertex]
	if verticesToG1 is not None:
		verticesFromG2 = graph[G2][vertex]
		if verticesFromG2 is not None:
			for toVertex in verticesFromG2:
				verticesFromG3 = graph[G3][toVertex]
				if verticesFromG3 is not None:
					count = count + len(verticesToG1.intersection(verticesFromG3))
print(count)