Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.

There are $n_1$ different types of first courses Ivan can buy (the $i$-th of them costs $a_i$ coins), $n_2$ different types of second courses (the $i$-th of them costs $b_i$ coins), $n_3$ different types of drinks (the $i$-th of them costs $c_i$ coins) and $n_4$ different types of desserts (the $i$-th of them costs $d_i$ coins).

Some dishes don't go well with each other. There are $m_1$ pairs of first courses and second courses that don't go well with each other, $m_2$ pairs of second courses and drinks, and $m_3$ pairs of drinks and desserts that don't go well with each other.

Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!


-----Input-----

The first line contains four integers $n_1$, $n_2$, $n_3$ and $n_4$ ($1 \le n_i \le 150000$) — the number of types of first courses, second courses, drinks and desserts, respectively.

Then four lines follow. The first line contains $n_1$ integers $a_1, a_2, \dots, a_{n_1}$ ($1 \le a_i \le 10^8$), where $a_i$ is the cost of the $i$-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way ($1 \le b_i, c_i, d_i \le 10^8$).

The next line contains one integer $m_1$ ($0 \le m_1 \le 200000$) — the number of pairs of first and second courses that don't go well with each other. Each of the next $m_1$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i \le n_1$; $1 \le y_i \le n_2$) denoting that the first course number $x_i$ doesn't go well with the second course number $y_i$. All these pairs are different.

The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other ($0 \le m_2, m_3 \le 200000$).


-----Output-----

If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print $-1$. Otherwise, print one integer — the minimum total cost of the dinner.


-----Examples-----

Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1


-----Note-----

The best option in the first example is to take the first course $2$, the second course $1$, the drink $2$ and the dessert $1$.

In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.

Difficulty: HARD

Solutions:
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
(n1, n2, n3, n4) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
a = sorted(enumerate(A), key=lambda x: x[1])
b = sorted(enumerate(B), key=lambda x: x[1])
c = sorted(enumerate(C), key=lambda x: x[1])
d = sorted(enumerate(D), key=lambda x: x[1])
m1 = int(input())
m1set = set()
for i in range(m1):
	(x, y) = map(int, input().split())
	m1set.add((x, y))
m2 = int(input())
m2set = set()
for i in range(m2):
	(x, y) = map(int, input().split())
	m2set.add((x, y))
m3 = int(input())
m3set = set()
for i in range(m3):
	(x, y) = map(int, input().split())
	m3set.add((x, y))
bDic = defaultdict(lambda : -1)
for i in range(n2):
	for j in a:
		if (j[0] + 1, i + 1) in m1set:
			continue
		bDic[i] = j[0]
		break
cDic = defaultdict(lambda : -1)
cc = []
for i in range(n3):
	for j in d:
		if (i + 1, j[0] + 1) in m3set:
			continue
		cDic[i] = j[0]
		cc.append((i, C[i] + j[1]))
		break
out = 10 ** 9
cc.sort(key=lambda x: x[1])
for i in range(n2):
	if bDic[i] != -1:
		for j in cc:
			if (i + 1, j[0] + 1) in m2set:
				continue
			out = min(out, j[1] + B[i] + A[bDic[i]])
			break
if out < 10 ** 9:
	print(out)
else:
	print(-1)


import sys
input = sys.stdin.readline

def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
INF = int(1000000000.0)
n = list(read_ints())
a = [[] for _ in range(4)]
a[0] = list(read_ints())
a[1] = list(read_ints())
a[2] = list(read_ints())
a[3] = list(read_ints())
dp = [(a[0][i], i) for i in range(n[0])]
dp.sort()
for k in range(3):
	m = read_int()
	banned = [set() for _ in range(n[k + 1])]
	for _ in range(m):
		(u, v) = read_ints()
		banned[v - 1].add(u - 1)
	f = [INF] * n[k + 1]
	for i in range(n[k + 1]):
		for j in range(n[k]):
			if dp[j][1] not in banned[i]:
				f[i] = dp[j][0] + a[k + 1][i]
				break
	dp = [(f[i], i) for i in range(n[k + 1])]
	dp.sort()
print(dp[0][0] if dp[0][0] < INF else -1)


import sys
input = sys.stdin.readline
from operator import itemgetter
(n1, n2, n3, n4) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
AX = [(a, i) for (i, a) in enumerate(A)]
AX.sort(key=itemgetter(0))
DPB = [1 << 60] * n2
m2 = int(input())
BAN = [set() for i in range(n2)]
for i in range(m2):
	(x, y) = map(int, input().split())
	BAN[y - 1].add(x - 1)
for j in range(n2):
	for (a, i) in AX:
		if i in BAN[j]:
			continue
		else:
			DPB[j] = a + B[j]
			break
DPC = [1 << 60] * n3
m3 = int(input())
BAN = [set() for i in range(n3)]
for i in range(m3):
	(x, y) = map(int, input().split())
	BAN[y - 1].add(x - 1)
BX = [(a, i) for (i, a) in enumerate(DPB)]
BX.sort(key=itemgetter(0))
for j in range(n3):
	for (a, i) in BX:
		if i in BAN[j]:
			continue
		else:
			DPC[j] = a + C[j]
			break
DPD = [1 << 60] * n4
m4 = int(input())
BAN = [set() for i in range(n4)]
for i in range(m4):
	(x, y) = map(int, input().split())
	BAN[y - 1].add(x - 1)
CX = [(a, i) for (i, a) in enumerate(DPC)]
CX.sort(key=itemgetter(0))
for j in range(n4):
	for (a, i) in CX:
		if i in BAN[j]:
			continue
		else:
			DPD[j] = a + D[j]
			break
ANS = min(DPD)
if ANS >= 1 << 60:
	print(-1)
else:
	print(ANS)


import sys
input = sys.stdin.buffer.readline
inf = 10 ** 18
(n1, n2, n3, n4) = map(int, input().split())
X = list(map(int, input().split()))
X = [(i, X[i]) for i in range(n1)]
X.sort(key=lambda x: x[1])
Y = list(map(int, input().split()))
Z = list(map(int, input().split()))
W = list(map(int, input().split()))
(m1,) = map(int, input().split())
V = [set() for _ in range(n2)]
for _ in range(m1):
	(a, b) = map(int, input().split())
	V[b - 1].add(a - 1)
for i in range(n2):
	for (j, x) in X:
		if j not in V[i]:
			Y[i] += x
			break
	else:
		Y[i] = inf
Y = [(i, Y[i]) for i in range(n2)]
Y.sort(key=lambda x: x[1])
(m1,) = map(int, input().split())
V = [set() for _ in range(n3)]
for _ in range(m1):
	(a, b) = map(int, input().split())
	V[b - 1].add(a - 1)
for i in range(n3):
	for (j, x) in Y:
		if j not in V[i]:
			Z[i] += x
			break
	else:
		Z[i] = inf
Z = [(i, Z[i]) for i in range(n3)]
Z.sort(key=lambda x: x[1])
(m1,) = map(int, input().split())
V = [set() for _ in range(n4)]
for _ in range(m1):
	(a, b) = map(int, input().split())
	V[b - 1].add(a - 1)
for i in range(n4):
	for (j, x) in Z:
		if j not in V[i]:
			W[i] += x
			break
	else:
		W[i] = inf
W.sort()
if W[0] >= inf:
	print(-1)
else:
	print(W[0])


import sys
import bisect
from collections import defaultdict
from io import BytesIO, IOBase

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().split(' ')

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	n = get_int()
	a = get_ints()
	return n - a.count(min(a))

def solve_b():
	(n, k) = get_ints()
	if n % 2 == 0:
		return (k - 1) % n + 1
	else:
		return (k + (k - 1) // (n // 2) - 1) % n + 1

def solve_c():
	n = get_int()
	ans = []
	if n % 2 == 1:
		for team in range(n):
			ans.extend([(-1) ** i for i in range(n - team - 1)])
	else:
		for team in range(n):
			ans.extend([(-1) ** i - int(i == 0 and team % 2 == 0) for i in range(n - team - 1)])
	return ans

def solve_d():
	c_vals = [5]
	i = 5
	while c_vals[-1] < 10 ** 9 + 1:
		c_vals.append((i ** 2 - 1) // 2 + 1)
		i += 2
	t = get_int()
	r = []
	for _ in range(t):
		n = get_int()
		r.append(bisect.bisect_right(c_vals, n))
	return r

def solve_e():
	n = get_ints()
	costs = [[(x, j) for (j, x) in enumerate(get_ints())] for _ in range(4)]
	mismatch_graph = [defaultdict(set) for _ in range(3)]
	for course_trans in range(3):
		for mismatch in range(get_int()):
			(a, b) = get_ints()
			mismatch_graph[course_trans][b - 1].add(a - 1)
	dp = [sorted(costs[0])]
	for j in range(3):
		tmp = []
		for l in range(n[j + 1]):
			k = 0
			while k < n[j]:
				if costs[j + 1][l][-1] in mismatch_graph[j] and dp[-1][k][-1] in mismatch_graph[j][costs[j + 1][l][-1]]:
					k += 1
				else:
					break
			if k == n[j]:
				tmp.append((float('inf'), costs[j + 1][l][-1]))
			else:
				tmp.append((costs[j + 1][l][0] + dp[-1][k][0], costs[j + 1][l][-1]))
		dp.append(sorted(tmp))
		if dp[-1][0][0] == float('inf'):
			return -1
	return dp[-1][0][0]
print(solve_e())


import sys, os
import math
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def MI():
	return map(int, input().split())

def out(var):
	sys.stdout.write(str(var) + '\n')
from collections import defaultdict
(n1, n2, n3, n4) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
a = sorted(enumerate(A), key=lambda x: x[1])
b = sorted(enumerate(B), key=lambda x: x[1])
c = sorted(enumerate(C), key=lambda x: x[1])
d = sorted(enumerate(D), key=lambda x: x[1])
m1 = int(input())
m1set = set()
for i in range(m1):
	(x, y) = map(int, input().split())
	m1set.add((x, y))
m2 = int(input())
m2set = set()
for i in range(m2):
	(x, y) = map(int, input().split())
	m2set.add((x, y))
m3 = int(input())
m3set = set()
for i in range(m3):
	(x, y) = map(int, input().split())
	m3set.add((x, y))
bDic = defaultdict(lambda : -1)
for i in range(n2):
	for j in a:
		if (j[0] + 1, i + 1) in m1set:
			continue
		bDic[i] = j[0]
		break
cDic = defaultdict(lambda : -1)
cc = []
for i in range(n3):
	for j in d:
		if (i + 1, j[0] + 1) in m3set:
			continue
		cDic[i] = j[0]
		cc.append((i, C[i] + j[1]))
		break
out = 10 ** 9
cc.sort(key=lambda x: x[1])
for i in range(n2):
	if bDic[i] != -1:
		for j in cc:
			if (i + 1, j[0] + 1) in m2set:
				continue
			out = min(out, j[1] + B[i] + A[bDic[i]])
			break
if out < 10 ** 9:
	print(out)
else:
	print(-1)


from collections import defaultdict

def dp_calc(prev_costs, n1, n2, edges, cur_costs):
	new_prev_costs = [(cost, idx + 1) for (idx, cost) in enumerate(prev_costs)]
	new_prev_costs.sort()
	dp = []
	graph = defaultdict(set)
	for (start, end) in edges:
		graph[end].add(start)
	for i in range(1, n2 + 1):
		cur_idx = 0
		while cur_idx < n1 and new_prev_costs[cur_idx][1] in graph[i]:
			cur_idx += 1
		if cur_idx == n1:
			dp.append(float('inf'))
		else:
			dp.append(new_prev_costs[cur_idx][0] + cur_costs[i - 1])
	return dp

def main():
	(n1, n2, n3, n4) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = list(map(int, input().split(' ')))
	d = list(map(int, input().split(' ')))
	m1 = int(input())
	edges1 = []
	for _ in range(m1):
		(x, y) = map(int, input().split(' '))
		edges1.append((x, y))
	m2 = int(input())
	edges2 = []
	for _ in range(m2):
		(x, y) = map(int, input().split(' '))
		edges2.append((x, y))
	m3 = int(input())
	edges3 = []
	for _ in range(m3):
		(x, y) = map(int, input().split(' '))
		edges3.append((x, y))
	b = dp_calc(a, n1, n2, edges1, b)
	c = dp_calc(b, n2, n3, edges2, c)
	d = dp_calc(c, n3, n4, edges3, d)
	ans = min(d)
	if ans == float('inf'):
		print(-1)
	else:
		print(ans)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
from sys import stdin
n = list(map(int, stdin.readline().split()))
a = [list(map(int, stdin.readline().split())) for i in range(4)]
v = [set([]) for i in range(3)]
for i in range(3):
	m = int(stdin.readline())
	for j in range(m):
		(x, y) = map(int, stdin.readline().split())
		x -= 1
		y -= 1
		v[i].add((x, y))
dp = [[float('inf')] * len(a[i]) for i in range(4)]
dp[0] = a[0]
for i in range(1, 4):
	lai = [(dp[i - 1][j], j) for j in range(len(a[i - 1]))]
	lai.sort()
	remR = [i for i in range(len(a[i]))]
	for (cost, lv) in lai:
		nexR = []
		for rv in remR:
			if (lv, rv) not in v[i - 1]:
				dp[i][rv] = cost + a[i][rv]
			else:
				nexR.append(rv)
		remR = nexR
		if len(remR) == 0:
			break
ans = min(dp[-1])
if ans == float('inf'):
	print(-1)
else:
	print(ans)


import sys
input = sys.stdin.readline
input()
INF = 10 ** 18
prev = list(map(int, input().split()))
As = [list(map(int, input().split())) for _ in range(3)]
for nex in As:
	order = sorted(range(len(prev)), key=prev.__getitem__)
	nadj = [set() for _ in range(len(nex))]
	for _ in range(int(input())):
		(x, y) = map(lambda s: int(s) - 1, input().split())
		nadj[y].add(x)
	for i in range(len(nex)):
		j = 0
		while j < len(order) and order[j] in nadj[i]:
			j += 1
		nex[i] = min(INF, nex[i] + (prev[order[j]] if j < len(order) else INF))
	prev = nex
r = min(prev)
print(-1 if r == INF else r)


import sys
input = sys.stdin.readline
import math
INF = 10 ** 18

def segfunc(x, y):
	return min(x, y)
ide_ele = INF

class SegTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res
(n1, n2, n3, n4) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
m1 = int(input())
order1 = [[-1] for _ in range(n2)]
for i in range(m1):
	(x, y) = map(int, input().split())
	order1[y - 1].append(x - 1)
for i in order1:
	i.sort()
	i.append(n1)
m2 = int(input())
order2 = [[-1] for _ in range(n3)]
for i in range(m2):
	(x, y) = map(int, input().split())
	order2[y - 1].append(x - 1)
for i in order2:
	i.sort()
	i.append(n2)
m3 = int(input())
order3 = [[-1] for _ in range(n4)]
for i in range(m3):
	(x, y) = map(int, input().split())
	order3[y - 1].append(x - 1)
for i in order3:
	i.sort()
	i.append(n3)
min_cost_2 = [INF] * n2
min_cost_3 = [INF] * n3
min_cost_4 = [INF] * n4
seg1 = SegTree(a, segfunc, ide_ele)
for i in range(n2):
	temp = INF
	for j in range(len(order1[i]) - 1):
		left = order1[i][j] + 1
		right = order1[i][j + 1]
		check = seg1.query(left, right)
		temp = min(check, temp)
	min_cost_2[i] = temp
for i in range(n2):
	b[i] = min(min_cost_2[i] + b[i], INF)
seg2 = SegTree(b, segfunc, ide_ele)
for i in range(n3):
	temp = INF
	for j in range(len(order2[i]) - 1):
		left = order2[i][j] + 1
		right = order2[i][j + 1]
		check = seg2.query(left, right)
		temp = min(check, temp)
	min_cost_3[i] = temp
for i in range(n3):
	c[i] = min(min_cost_3[i] + c[i], INF)
seg3 = SegTree(c, segfunc, ide_ele)
for i in range(n4):
	temp = INF
	for j in range(len(order3[i]) - 1):
		left = order3[i][j] + 1
		right = order3[i][j + 1]
		check = seg3.query(left, right)
		temp = min(check, temp)
	min_cost_4[i] = temp
for i in range(n4):
	d[i] = min(min_cost_4[i] + d[i], INF)
ans = min(d)
if ans >= INF:
	print(-1)
else:
	print(ans)


import sys
from collections import defaultdict
MAX_PRICE = 500000000

def read_ints():
	return [int(i) for i in sys.stdin.readline().strip().split()]

def read_int():
	return int(sys.stdin.readline().strip())
(n1, n2, n3, n4) = read_ints()
firsts = read_ints()
firsts = sorted(((f, i + 1) for (i, f) in enumerate(firsts)))
seconds = read_ints()
seconds = sorted(((f, i + 1) for (i, f) in enumerate(seconds)))
drinks = read_ints()
drinks = sorted(((f, i + 1) for (i, f) in enumerate(drinks)))
desserts = read_ints()
desserts = sorted(((f, i + 1) for (i, f) in enumerate(desserts)))
bad_12 = defaultdict(set)
bad_23 = defaultdict(set)
bad_34 = defaultdict(set)
m1 = read_int()
for i in range(m1):
	(first, second) = read_ints()
	bad_12[first].add(second)
m2 = read_int()
for i in range(m2):
	(second, drink) = read_ints()
	bad_23[second].add(drink)
m3 = read_int()
for i in range(m3):
	(drink, dess) = read_ints()
	bad_34[drink].add(dess)
drink_prices = []
for (dr_price, dr_num) in drinks:
	for (des_price, des_num) in desserts:
		if des_num not in bad_34[dr_num]:
			drink_prices.append((dr_price + des_price, dr_num))
			break
	else:
		drink_prices.append((MAX_PRICE, dr_num))
drink_prices.sort()
second_prices = []
for (sec_price, sec_num) in seconds:
	for (dr_price, dr_num) in drink_prices:
		if dr_num not in bad_23[sec_num]:
			second_prices.append((sec_price + dr_price, sec_num))
			break
	else:
		second_prices.append((MAX_PRICE, sec_num))
second_prices.sort()
first_prices = []
for (fir_price, fir_num) in firsts:
	for (sec_price, sec_num) in second_prices:
		if sec_num not in bad_12[fir_num]:
			first_prices.append((fir_price + sec_price, fir_num))
			break
	else:
		first_prices.append((MAX_PRICE, fir_num))
best = min(first_prices)
if best[0] >= MAX_PRICE:
	print(-1)
else:
	print(best[0])


import collections
(n1, n2, n3, n4) = map(int, input().split())
arr = []
for _ in range(4):
	arr.append(list(map(int, input().split())))
d = collections.defaultdict(set)
for i in range(3):
	m = int(input())
	for _ in range(m):
		(x, y) = map(int, input().split())
		d[i, x - 1].add(y - 1)
for i in range(2, 0, -1):
	a = arr[i + 1]
	p = sorted(list(range(len(a))), key=lambda x: a[x])
	for c in range(len(arr[i])):
		j = 0
		while j < len(a) and p[j] in d[i, c] and (arr[i + 1][p[j]] < float('inf')):
			j += 1
		if j == len(a) or arr[i + 1][p[j]] == float('inf'):
			arr[i][c] = float('inf')
		else:
			arr[i][c] += arr[i + 1][p[j]]
ans = float('inf')
a = arr[1]
ap = sorted(list(range(len(a))), key=lambda x: a[x])
b = arr[0]
bp = sorted(list(range(len(b))), key=lambda x: b[x])
for c in bp:
	if b[c] >= ans:
		break
	if ap and a[ap[0]] + b[c] >= ans:
		break
	else:
		while ap and a[ap[-1]] >= ans:
			ap.pop()
		j = 0
		while j < len(ap) and ap[j] in d[0, c]:
			j += 1
		if j < len(ap):
			ans = min(ans, a[ap[j]] + b[c])
print(-1 if ans == float('inf') else ans)


import sys
input = sys.stdin.buffer.readline
INF = int(1000000000.0)
n = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(4)]
dp = [[a[0][i], i] for i in range(n[0])]
dp.sort()
for i in range(3):
	joint = [set() for j in range(n[i + 1])]
	k = int(input())
	for j in range(k):
		(x, y) = map(int, input().split())
		joint[y - 1].add(x - 1)
	p = [INF for i in range(n[i + 1])]
	for j in range(n[i + 1]):
		for l in range(n[i]):
			if dp[l][1] not in joint[j]:
				p[j] = dp[l][0] + a[i + 1][j]
				break
	dp = [[p[j], j] for j in range(n[i + 1])]
	dp.sort()
if dp[0][0] >= INF:
	print(-1)
else:
	print(dp[0][0])


from collections import defaultdict
from copy import deepcopy
from heapq import heapify, heappop
from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()
INF = 1000000000

def main():
	(n1, n2, n3, n4) = map(int, input().split())
	aa = [int(a) for a in input().split()]
	bb = [int(a) for a in input().split()]
	cc = [int(a) for a in input().split()]
	dd = [int(a) for a in input().split()]
	m1 = int(input())
	bab = defaultdict(set)
	for _ in range(m1):
		(x, y) = map(int, input().split())
		bab[x - 1].add(y - 1)
	m2 = int(input())
	bbc = defaultdict(set)
	for _ in range(m2):
		(x, y) = map(int, input().split())
		bbc[x - 1].add(y - 1)
	m3 = int(input())
	bcd = defaultdict(set)
	for _ in range(m3):
		(x, y) = map(int, input().split())
		bcd[x - 1].add(y - 1)
	mindcosts = dd
	minccosts = min_costs(bcd, cc, mindcosts, n4)
	minbcosts = min_costs(bbc, bb, minccosts, n3)
	minacosts = min_costs(bab, aa, minbcosts, n2)
	if min(minacosts) >= INF:
		print(-1)
	else:
		print(min(minacosts))

def min_costs(bcd, cc, mindcosts, n4):
	minccosts = []
	dord = list(sorted(range(n4), key=lambda i: mindcosts[i]))
	for (i, c) in enumerate(cc):
		for d in dord:
			if d not in bcd[i]:
				minccosts.append(c + mindcosts[d])
				break
		else:
			minccosts.append(INF)
	return minccosts
main()


import sys
input = sys.stdin.readline
n = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
m1 = int(input())
set_xy1 = set()
for _ in range(m1):
	(x, y) = map(int, input().split())
	set_xy1.add((x - 1, y - 1))
m2 = int(input())
set_xy2 = set()
for _ in range(m2):
	(x, y) = map(int, input().split())
	set_xy2.add((x - 1, y - 1))
m3 = int(input())
set_xy3 = set()
for _ in range(m3):
	(x, y) = map(int, input().split())
	set_xy3.add((x - 1, y - 1))
sortedA = []
for (ia, a) in enumerate(A):
	sortedA.append([a, ia])
sortedA.sort()
sortedB = []
for (ib, b) in enumerate(B):
	for (a, ia) in sortedA:
		if (ia, ib) in set_xy1:
			continue
		sortedB.append([a + b, ib])
		break
sortedB.sort()
sortedC = []
for (ic, c) in enumerate(C):
	for (b, ib) in sortedB:
		if (ib, ic) in set_xy2:
			continue
		sortedC.append([b + c, ic])
		break
sortedC.sort()
sortedD = []
for (id, d) in enumerate(D):
	for (c, ic) in sortedC:
		if (ic, id) in set_xy3:
			continue
		sortedD.append([c + d, id])
		break
sortedD.sort()
if len(sortedD) == 0:
	print(-1)
else:
	print(sortedD[0][0])


import io
import os
from collections import defaultdict

class SegmentTree:

	def __init__(self, data, default=0, func=max):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		start += self._size
		stop += self._size
		res_left = res_right = self._default
		while start < stop:
			if start & 1:
				res_left = self._func(res_left, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res_right = self._func(self.data[stop], res_right)
			start >>= 1
			stop >>= 1
		return self._func(res_left, res_right)

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
inf = float('inf')

def solve(A, B, C, D, M1, M2, M3):

	def groupBadPrev(M):
		d = defaultdict(list)
		for (x, y) in M:
			x -= 1
			y -= 1
			d[y].append(x)
		return d
	dp = list(A)
	courses = [B, C, D]
	badPrevs = [groupBadPrev(M1), groupBadPrev(M2), groupBadPrev(M3)]
	for (course, badPrev) in zip(courses, badPrevs):
		prevDp = dp
		segTree = SegmentTree(prevDp, inf, min)
		dp = [inf] * len(course)
		bestA = segTree.query(0, len(segTree))
		for b in range(len(course)):
			if b in badPrev:
				for a in badPrev[b]:
					segTree[a] = inf
				dp[b] = segTree.query(0, len(segTree)) + course[b]
				for a in badPrev[b]:
					segTree[a] = prevDp[a]
			else:
				dp[b] = bestA + course[b]
	ans = min(dp)
	if ans == inf:
		return -1
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = 1
for tc in range(1, TC + 1):
	(N1, N2, N3, N4) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	C = [int(x) for x in input().split()]
	D = [int(x) for x in input().split()]
	(M,) = [int(x) for x in input().split()]
	M1 = [[int(x) for x in input().split()] for i in range(M)]
	(M,) = [int(x) for x in input().split()]
	M2 = [[int(x) for x in input().split()] for i in range(M)]
	(M,) = [int(x) for x in input().split()]
	M3 = [[int(x) for x in input().split()] for i in range(M)]
	ans = solve(A, B, C, D, M1, M2, M3)
	print(ans)


import heapq
import sys
input = iter(sys.stdin.read().splitlines()).__next__
(n_1, n_2, n_3, n_4) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
costs_1 = [(a_i, i) for (i, a_i) in enumerate(a)]
heapq.heapify(costs_1)
costs_2 = [float('inf') for _ in range(n_2)]
bad_21 = {}
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if y - 1 not in bad_21:
		bad_21[y - 1] = set()
	bad_21[y - 1].add(x - 1)
for y in range(n_2):
	if y not in bad_21:
		(min_a, _) = costs_1[0]
		costs_2[y] = b[y] + min_a
	else:
		removed = []
		while len(costs_1) and costs_1[0][1] in bad_21[y]:
			removed.append(heapq.heappop(costs_1))
		if len(costs_1):
			(best_a, _) = costs_1[0]
			costs_2[y] = b[y] + best_a
		for e in removed:
			heapq.heappush(costs_1, e)
costs_2 = [(b_i, i) for (i, b_i) in enumerate(costs_2)]
heapq.heapify(costs_2)
n_1 = n_2
n_2 = n_3
a = b
b = c
costs_1 = costs_2
costs_2 = [float('inf') for _ in range(n_2)]
bad_21 = {}
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if y - 1 not in bad_21:
		bad_21[y - 1] = set()
	bad_21[y - 1].add(x - 1)
for y in range(n_2):
	if y not in bad_21:
		(min_a, _) = costs_1[0]
		costs_2[y] = b[y] + min_a
	else:
		removed = []
		while len(costs_1) and costs_1[0][1] in bad_21[y]:
			removed.append(heapq.heappop(costs_1))
		if len(costs_1):
			(best_a, _) = costs_1[0]
			costs_2[y] = b[y] + best_a
		for e in removed:
			heapq.heappush(costs_1, e)
costs_2 = [(b_i, i) for (i, b_i) in enumerate(costs_2)]
heapq.heapify(costs_2)
n_1 = n_3
n_2 = n_4
a = c
b = d
costs_1 = costs_2
costs_2 = [float('inf') for _ in range(n_2)]
bad_21 = {}
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if y - 1 not in bad_21:
		bad_21[y - 1] = set()
	bad_21[y - 1].add(x - 1)
for y in range(n_2):
	if y not in bad_21:
		(min_a, _) = costs_1[0]
		costs_2[y] = b[y] + min_a
	else:
		removed = []
		while len(costs_1) and costs_1[0][1] in bad_21[y]:
			removed.append(heapq.heappop(costs_1))
		if len(costs_1):
			(best_a, _) = costs_1[0]
			costs_2[y] = b[y] + best_a
		for e in removed:
			heapq.heappush(costs_1, e)
best_cost = min(costs_2)
if best_cost > 10 ** 8 * 4:
	print(-1)
else:
	print(best_cost)


import os, sys
from io import BytesIO, IOBase
from math import inf, isinf

def some_random_function():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def main():
	n = list(map(int, input().split()))
	cost = [list(map(int, input().split())) for _ in range(4)]
	op = [[] for _ in range(3)]
	for i in range(3):
		for _ in range(int(input())):
			op[i].append(tuple(map(int, input().split())))
	for i in range(2, -1, -1):
		band = [[] for _ in range(n[i + 1] + 1)]
		for j in op[i]:
			band[j[1]].append(j[0])
		ke = sorted(range(n[i + 1]), key=lambda xx: cost[i + 1][xx])
		z = min(cost[i + 1])
		cost1 = cost[i]
		for k in range(len(cost1)):
			cost1[k] += z
		addi = [0] * n[i]
		for (ind, k) in enumerate(ke):
			for z in band[k + 1]:
				if addi[z - 1] == ind and (not isinf(cost1[z - 1])):
					cost1[z - 1] -= cost[i + 1][k]
					cost1[z - 1] += inf if ind == len(ke) - 1 else cost[i + 1][ke[ind + 1]]
					addi[z - 1] = ind + 1
	mini = min(cost[0])
	if isinf(mini):
		print(-1)
	else:
		print(mini)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def some_random_function1():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function2():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function3():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function4():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
main()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=10 ** 9, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n1, n2, n3, n4) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
s = SegmentTree(l1)
m1 = int(input())
e = 10 ** 9 + 5
dp = [0] * n2
sw = defaultdict(set)
for i in range(m1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	sw[b].add(a)
for i in range(n2):
	for j in sw[i]:
		s.__setitem__(j, e + 1)
	dp[i] = s.query(0, n1 - 1) + l2[i]
	for j in sw[i]:
		s.__setitem__(j, l1[j])
m2 = int(input())
dp1 = [0] * n3
s = SegmentTree(dp)
sw = defaultdict(set)
for i in range(m2):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	sw[b].add(a)
for i in range(n3):
	for j in sw[i]:
		s.__setitem__(j, e + 1)
	dp1[i] = s.query(0, n2 - 1) + l3[i]
	for j in sw[i]:
		s.__setitem__(j, dp[j])
m3 = int(input())
dp2 = [0] * n4
sw = defaultdict(set)
s = SegmentTree(dp1)
for i in range(m3):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	sw[b].add(a)
for i in range(n4):
	for j in sw[i]:
		s.__setitem__(j, e + 1)
	dp2[i] = s.query(0, n3 - 1) + l4[i]
	for j in sw[i]:
		s.__setitem__(j, dp1[j])
ans = min(dp2)
if ans >= 10 ** 9:
	ans = -1
print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
n = list(map(int, input().split()))
a = []
for i in range(4):
	a.append(list(map(int, input().split())))

def solve(l1, l2):
	m = int(input())
	not_together = [[i, set()] for i in range(n[l1])]
	for i in range(m):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		not_together[x][1].add(y)
	not_together = sorted(not_together, key=lambda x: a[l1][x[0]])
	for i in range(n[l2]):
		ans = float('inf')
		for j in range(len(not_together)):
			if i not in not_together[j][1]:
				ans = a[l1][not_together[j][0]]
				break
		a[l2][i] += ans
solve(0, 1)
solve(1, 2)
solve(2, 3)
ans = min(a[3])
if ans == float('inf'):
	print(-1)
else:
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd
(N1, N2, N3, N4) = [int(s) for s in input().split()]
(A, B, C, D) = ([int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()])
A = [(a, i) for (i, a) in enumerate(A)]
B = [(a, i) for (i, a) in enumerate(B)]
C = [(a, i) for (i, a) in enumerate(C)]
D = [(a, i) for (i, a) in enumerate(D)]
A.sort()
m1 = dd(set)
m2 = dd(set)
m3 = dd(set)
M1 = int(input())
for m in range(M1):
	(x, y) = [int(s) for s in input().split()]
	x -= 1
	y -= 1
	m1[y].add(x)
M2 = int(input())
for m in range(M2):
	(x, y) = [int(s) for s in input().split()]
	x -= 1
	y -= 1
	m2[y].add(x)
M3 = int(input())
for m in range(M3):
	(x, y) = [int(s) for s in input().split()]
	x -= 1
	y -= 1
	m3[y].add(x)
NEW_A = []
for j in range(N2):
	idx = 0
	while idx < len(A) and A[idx][1] in m1[B[j][1]]:
		idx += 1
	if idx < N1:
		NEW_A.append((A[idx][0] + B[j][0], B[j][1]))
if not NEW_A:
	print(-1)
	sys.exit(0)
NEW_A.sort()
NEW_B = []
for j in range(N3):
	idx = 0
	while idx < len(NEW_A) and NEW_A[idx][1] in m2[C[j][1]]:
		idx += 1
	if idx < len(NEW_A):
		NEW_B.append((NEW_A[idx][0] + C[j][0], C[j][1]))
if not NEW_B:
	print(-1)
	sys.exit(0)
NEW_B.sort()
ans = 10 ** 18
for j in range(N4):
	idx = 0
	while idx < len(NEW_B) and NEW_B[idx][1] in m3[D[j][1]]:
		idx += 1
	if idx < len(NEW_B):
		ans = min(ans, NEW_B[idx][0] + D[j][0])
print(ans if ans < 10 ** 18 else -1)


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def floor_sum(n: int, m: int, a: int, b: int) -> int:
	ans = 0
	if a >= m:
		ans += (n - 1) * n * (a // m) // 2
		a %= m
	if b >= m:
		ans += n * (b // m)
		b %= m
	y_max = (a * n + b) // m
	x_max = y_max * m - b
	if y_max == 0:
		return ans
	ans += (n - (x_max + a - 1) // a) * y_max
	ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
	return ans

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n):
		self.BIT = [0] * (n + 1)
		self.num = n

	def query(self, idx):
		res_sum = 0
		while idx > 0:
			res_sum += self.BIT[idx]
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		while idx <= self.num:
			self.BIT[idx] += x
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matrix[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matrix[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matrix[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] + other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] - other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matrix[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matrix[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matrix[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)

class SegmentTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += self.num
		r += self.num
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.tree[l] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.tree[r - 1] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		elif Rmin != -1:
			pos = Rmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		else:
			return -1

class DualSegmentTree:

	def __init__(self, n, segfunc, ide_ele):
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num

	def update(self, l, r, x):
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				self.tree[l] = self.segfunc(self.tree[l], x)
				l += 1
			if r & 1:
				self.tree[r - 1] = self.segfunc(self.tree[r - 1], x)
			l >>= 1
			r >>= 1

	def __getitem__(self, idx):
		idx += self.num
		res = self.ide_ele
		while idx:
			res = self.segfunc(res, self.tree[idx])
			idx >>= 1
		return res

class LazySegmentTree:
	__slots__ = ['merge', 'merge_unit', 'operate', 'merge_operate', 'operate_unit', 'n', 'data', 'lazy']

	def __init__(self, n, init, merge, merge_unit, operate, merge_operate, operate_unit):
		self.merge = merge
		self.merge_unit = merge_unit
		self.operate = operate
		self.merge_operate = merge_operate
		self.operate_unit = operate_unit
		self.n = (n - 1).bit_length()
		self.data = [merge_unit for i in range(1 << self.n + 1)]
		self.lazy = [operate_unit for i in range(1 << self.n + 1)]
		if init:
			for i in range(n):
				self.data[2 ** self.n + i] = init[i]
			for i in range(2 ** self.n - 1, 0, -1):
				self.data[i] = self.merge(self.data[2 * i], self.data[2 * i + 1])

	def propagate(self, v):
		ope = self.lazy[v]
		if ope == self.operate_unit:
			return
		self.lazy[v] = self.operate_unit
		self.data[v << 1] = self.operate(self.data[v << 1], ope)
		self.data[(v << 1) + 1] = self.operate(self.data[(v << 1) + 1], ope)
		self.lazy[v << 1] = self.merge_operate(self.lazy[v << 1], ope)
		self.lazy[(v << 1) + 1] = self.merge_operate(self.lazy[(v << 1) + 1], ope)

	def propagate_above(self, i):
		m = i.bit_length() - 1
		for bit in range(m, 0, -1):
			v = i >> bit
			self.propagate(v)

	def remerge_above(self, i):
		while i:
			c = self.merge(self.data[i], self.data[i ^ 1])
			i >>= 1
			self.data[i] = self.operate(c, self.lazy[i])

	def update(self, l, r, x):
		l += 1 << self.n
		r += 1 << self.n
		l0 = l // (l & -l)
		r0 = r // (r & -r) - 1
		self.propagate_above(l0)
		self.propagate_above(r0)
		while l < r:
			if l & 1:
				self.data[l] = self.operate(self.data[l], x)
				self.lazy[l] = self.merge_operate(self.lazy[l], x)
				l += 1
			if r & 1:
				self.data[r - 1] = self.operate(self.data[r - 1], x)
				self.lazy[r - 1] = self.merge_operate(self.lazy[r - 1], x)
			l >>= 1
			r >>= 1
		self.remerge_above(l0)
		self.remerge_above(r0)

	def query(self, l, r):
		l += 1 << self.n
		r += 1 << self.n
		l0 = l // (l & -l)
		r0 = r // (r & -r) - 1
		self.propagate_above(l0)
		self.propagate_above(r0)
		res = self.merge_unit
		while l < r:
			if l & 1:
				res = self.merge(res, self.data[l])
				l += 1
			if r & 1:
				res = self.merge(res, self.data[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += 1 << self.n
		r += 1 << self.n
		l0 = l // (l & -l)
		r0 = r // (r & -r) - 1
		self.propagate_above(l0)
		self.propagate_above(r0)
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.data[l][0] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.data[r - 1][0] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		res = -1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				self.propagate(pos)
				if self.data[2 * pos][0] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			res = pos - self.num
		if Rmin != -1:
			pos = Rmin
			while pos < self.num:
				self.propagate(pos)
				if self.data[2 * pos][0] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			if res == -1:
				res = pos - self.num
			else:
				res = min(res, pos - self.num)
		return res
import sys
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.buffer.readline()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(1):
	n = li()
	a = li()
	b = li()
	c = li()
	d = li()
	food = a + b + c + d
	m1 = int(input())
	ab = [set() for i in range(n[0])]
	for i in range(m1):
		(x, y) = mi()
		ab[x - 1].add(y + n[0] - 1)
	m2 = int(input())
	bc = [set() for i in range(n[1])]
	for i in range(m2):
		(x, y) = mi()
		bc[x - 1].add(y + n[0] + n[1] - 1)
	m3 = int(input())
	cd = [set() for i in range(n[2])]
	for i in range(m3):
		(x, y) = mi()
		cd[x - 1].add(y + n[0] + n[1] + n[2] - 1)
	dp = [food[i] for i in range(len(food))]
	que = [(food[i], i) for i in range(n[0] + n[1] + n[2], n[0] + n[1] + n[2] + n[3])]
	heapify(que)
	for i in range(n[0] + n[1], n[0] + n[1] + n[2]):
		memo = []
		while que:
			(val, idx) = heappop(que)
			memo.append((val, idx))
			if idx in cd[i - n[0] - n[1]]:
				continue
			else:
				dp[i] += dp[idx]
				break
		else:
			dp[i] = 10 ** 17
		for a in memo:
			heappush(que, a)
	que = [(dp[i], i) for i in range(n[0] + n[1], n[0] + n[1] + n[2])]
	heapify(que)
	for i in range(n[0], n[0] + n[1]):
		memo = []
		while que:
			(val, idx) = heappop(que)
			memo.append((val, idx))
			if idx in bc[i - n[0]]:
				continue
			else:
				dp[i] += dp[idx]
				break
		else:
			dp[i] = 10 ** 17
		for a in memo:
			heappush(que, a)
	que = [(dp[i], i) for i in range(n[0], n[0] + n[1])]
	heapify(que)
	for i in range(n[0]):
		memo = []
		while que:
			(val, idx) = heappop(que)
			memo.append((val, idx))
			if idx in ab[i]:
				continue
			else:
				dp[i] += dp[idx]
				break
		else:
			dp[i] = 10 ** 17
		for a in memo:
			heappush(que, a)
	ans = min(dp[:n[0]])
	if ans >= 10 ** 17:
		print(-1)
	else:
		print(ans)


from sys import stdin, stdout
from collections import defaultdict
import math

def main():
	MODU = 10 ** 9 + 7
	(a, b, c, d) = list(map(int, stdin.readline().split()))
	T_A = list(map(int, stdin.readline().split()))
	T_B = list(map(int, stdin.readline().split()))
	T_C = list(map(int, stdin.readline().split()))
	T_D = list(map(int, stdin.readline().split()))
	NO_A = defaultdict(set)
	NO_B = defaultdict(set)
	NO_C = defaultdict(set)
	m = int(stdin.readline())
	for _ in range(m):
		(x, y) = list(map(int, stdin.readline().split()))
		NO_A[x].add(y)
	m = int(stdin.readline())
	for _ in range(m):
		(x, y) = list(map(int, stdin.readline().split()))
		NO_B[x].add(y)
	m = int(stdin.readline())
	for _ in range(m):
		(x, y) = list(map(int, stdin.readline().split()))
		NO_C[x].add(y)
	(A, B, C, D) = ([], [], [], [])
	for (i, x) in enumerate(T_A):
		A.append((x, i + 1))
	A.sort(key=lambda x: x[0])
	for (i, bb) in enumerate(T_B):
		pos_b = i + 1
		v = -1
		for (aa, pos_a) in A:
			if pos_b in NO_A[pos_a]:
				continue
			v = aa + bb
			break
		if v != -1:
			B.append((v, pos_b))
	B.sort(key=lambda x: x[0])
	for (i, cc) in enumerate(T_C):
		pos_c = i + 1
		v = -1
		for (bb, pos_b) in B:
			if pos_c in NO_B[pos_b]:
				continue
			v = bb + cc
			break
		if v != -1:
			C.append((v, pos_c))
	C.sort(key=lambda x: x[0])
	ans = 10 ** 9
	for (i, dd) in enumerate(T_D):
		pos_d = i + 1
		v = -1
		for (cc, pos_c) in C:
			if pos_d in NO_C[pos_c]:
				continue
			v = dd + cc
			break
		if v != -1:
			ans = min(ans, v)
	if ans == 10 ** 9:
		stdout.write('-1\n')
	else:
		stdout.write(str(ans) + '\n')
main()


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().strip()
n = list(map(int, input().split()))
a = []
for i in range(4):
	a.append(list(map(int, input().split())))

def solve_pair(i1, i2):
	m = int(input())
	not_together = [[i, set()] for i in range(n[i1])]
	for i in range(m):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		not_together[x][1].add(y)
	not_together = [v for v in sorted(not_together, key=lambda x: a[i1][x[0]])]
	for i in range(n[i2]):
		add = float('inf')
		for j in range(len(not_together)):
			if i not in not_together[j][1]:
				add = a[i1][not_together[j][0]]
				break
		a[i2][i] += add
solve_pair(0, 1)
solve_pair(1, 2)
solve_pair(2, 3)
ans = min(a[3])
if ans == float('inf'):
	print(-1)
else:
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from math import inf

def solve(c, d, tree3):
	e = sorted(range(len(d)), key=lambda x: d[x])
	for i in range(len(c)):
		f = 1
		for j in range(len(d)):
			if e[j] + 1 not in tree3[i + 1]:
				f = 0
				c[i] += d[e[j]]
				break
		if f:
			c[i] += inf

def inp():
	return list(map(int, input().split()))

def inptree(u, v):
	tree = [set() for _ in range(v + 1)]
	for i in range(u):
		(x, y) = map(int, input().split())
		tree[x].add(y)
	return tree

def main():
	(n1, n2, n3, n4) = map(int, input().split())
	(a, b, c, d) = (inp(), inp(), inp(), inp())
	(tree1, tree2, tree3) = (inptree(int(input()), n1), inptree(int(input()), n2), inptree(int(input()), n3))
	solve(c, d, tree3)
	solve(b, c, tree2)
	solve(a, b, tree1)
	mi = min(a)
	if mi == inf:
		print(-1)
	else:
		print(mi)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline

def main():
	n = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	prices = [a, b, c, d]
	inc = [{} for _ in range(3)]
	for i in range(3):
		ni = int(input())
		for _ in range(ni):
			(k, l) = map(int, input().split())
			if k - 1 in inc[i]:
				inc[i][k - 1].add(l - 1)
			else:
				inc[i][k - 1] = set([l - 1])
	step = 3
	mem2 = prices[3][:]
	for step in range(3, 0, -1):
		mem = mem2[:]
		index_sorted = sorted(range(n[step]), key=lambda x: mem[x])
		mem2 = [float('inf')] * n[step - 1]
		for i in range(n[step - 1]):
			index = 0
			while i in inc[step - 1] and index < n[step] and (index_sorted[index] in inc[step - 1][i]):
				index += 1
			if index < n[step]:
				mem2[i] = prices[step - 1][i] + mem[index_sorted[index]]
	rep = min(mem2)
	if rep < float('inf'):
		print(rep)
	else:
		print(-1)
main()


import sys
input = sys.stdin.readline
from math import sqrt
(n1, n2, n3, n4) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
m1 = int(input())
AB = [list(map(int, input().split())) for _ in range(m1)]
m2 = int(input())
BC = [list(map(int, input().split())) for _ in range(m2)]
m3 = int(input())
CD = [list(map(int, input().split())) for _ in range(m3)]

def cal(A, B, AB, n1, n2, ex):
	cand = sorted([(A[i], i) for (i, e) in enumerate(ex) if not e])
	invalid = [0] * n2
	G = [set() for _ in range(n2)]
	for (a, b) in AB:
		G[b - 1].add(a - 1)
	for i in range(n2):
		for (a, j) in cand:
			if j not in G[i]:
				B[i] += a
				break
		else:
			invalid[i] = 1
	if not invalid.count(0):
		print(-1)
		sys.exit()
	return invalid
invalid = cal(A, B, AB, n1, n2, [0] * n1)
invalid = cal(B, C, BC, n2, n3, invalid)
invalid = cal(C, D, CD, n3, n4, invalid)
ans = [d for (i, d) in enumerate(D) if not invalid[i]]
print(min(ans))


from sys import stdin, stdout
import collections, heapq, bisect, math
input = stdin.readline

def rint():
	return int(input())

def rstr():
	return input().strip()

def rlstr():
	return list(input().strip().split())

def rlint():
	return list(map(int, input().split()))

def main():
	n = rlint()
	a = rlint()
	b = rlint()
	c = rlint()
	d = rlint()
	price = [a, b, c, d]
	inc = [{} for _ in range(3)]
	for i in range(3):
		m = rint()
		for _ in range(m):
			(x, y) = rlint()
			x -= 1
			y -= 1
			if x not in inc[i]:
				inc[i][x] = set([y])
			else:
				inc[i][x].add(y)
	dp = price[-1][:]
	for step in range(3, 0, -1):
		dp2 = dp[:]
		dp = [float('inf')] * n[step - 1]
		index = sorted(range(n[step]), key=lambda i: dp2[i])
		for i in range(n[step - 1]):
			ind = 0
			while i in inc[step - 1] and ind < n[step] and (index[ind] in inc[step - 1][i]):
				ind += 1
			if ind < n[step]:
				dp[i] = price[step - 1][i] + dp2[index[ind]]
	res = min(dp)
	if res < float('inf'):
		print(res)
	else:
		print(-1)
main()


import sys
input = sys.stdin.readline

def main():
	N = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	C = [int(x) for x in input().split()]
	D = [int(x) for x in input().split()]
	M1 = int(input())
	set_XY1 = set()
	XY1 = [[int(x) for x in input().split()] for _ in range(M1)]
	for (x, y) in XY1:
		set_XY1.add((x - 1, y - 1))
	M2 = int(input())
	set_XY2 = set()
	XY2 = [[int(x) for x in input().split()] for _ in range(M2)]
	for (x, y) in XY2:
		set_XY2.add((x - 1, y - 1))
	M3 = int(input())
	set_XY3 = set()
	XY3 = [[int(x) for x in input().split()] for _ in range(M3)]
	for (x, y) in XY3:
		set_XY3.add((x - 1, y - 1))
	sorted_A = []
	for (i, a) in enumerate(A):
		sorted_A.append([a, i])
	sorted_A.sort()
	sorted_B = []
	for (ib, b) in enumerate(B):
		for (a, ia) in sorted_A:
			if (ia, ib) in set_XY1:
				continue
			sorted_B.append([a + b, ib])
			break
	sorted_B.sort()
	sorted_C = []
	for (ic, c) in enumerate(C):
		for (b, ib) in sorted_B:
			if (ib, ic) in set_XY2:
				continue
			sorted_C.append([b + c, ic])
			break
	sorted_C.sort()
	sorted_D = []
	for (id, d) in enumerate(D):
		for (c, ic) in sorted_C:
			if (ic, id) in set_XY3:
				continue
			sorted_D.append([d + c, id])
			break
	sorted_D.sort()
	if len(sorted_D) == 0:
		print(-1)
	else:
		print(sorted_D[0][0])
main()


import sys
input = sys.stdin.buffer.readline

def init(N, node, A, unit, func):
	n = 1
	while n < N:
		n <<= 1
	for i in range(n * 2 - 1):
		if len(node) <= i:
			node.append(unit)
		else:
			node[i] = unit
	for i in range(len(A)):
		node[n - 1 + i] = A[i]
	for i in range(n - 2, -1, -1):
		node[i] = func(node[(i << 1) + 1], node[(i << 1) + 2])
	node.append(func)
	node.append(unit)
	node.append(n)

def upd(node, x, a):
	y = node[-1] + x
	node[y - 1] = a
	while y > 1:
		y = y >> 1
		node[y - 1] = node[-3](node[(y << 1) - 1], node[y << 1])

def query(node, l, r):
	(x, y) = (l, r)
	z = node[-1] - 1
	rr = node[-2]
	rl = node[-2]
	while True:
		if x == y:
			return node[-3](rl, rr)
		if x & 1:
			rl = node[-3](rl, node[x + z])
			x += 1
		if y & 1:
			rr = node[-3](node[y + z - 1], rr)
		if z == 0:
			return node[-3](rl, rr)
		x >>= 1
		y >>= 1
		z >>= 1
INF = 10 ** 17
N = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(4)]
seg = [[] for i in range(4)]
for i in range(4):
	if i:
		init(N[i] + 1, seg[i], [], INF, lambda x, y: min(x, y))
	else:
		init(N[i] + 1, seg[i], C[i], INF, lambda x, y: min(x, y))
M = []
G = [[[] for j in range(N[i + 1])] for i in range(3)]
for i in range(3):
	M.append(int(input()))
	for j in range(M[i]):
		(a, b) = map(int, input().split())
		G[i][b - 1].append(a - 1)
for i in range(3):
	for j in range(N[i + 1]):
		Q = []
		for k in range(len(G[i][j])):
			Q.append(seg[i][G[i][j][k] + seg[i][-1] - 1])
			upd(seg[i], G[i][j][k], INF)
		upd(seg[i + 1], j, C[i + 1][j] + seg[i][0])
		for k in range(len(G[i][j])):
			upd(seg[i], G[i][j][k], Q[k])
if seg[3][0] >= INF:
	print(-1)
else:
	print(seg[3][0])


def main():
	(n1, n2, n3, n4) = readIntArr()
	a = readIntArr()
	b = readIntArr()
	c = readIntArr()
	d = readIntArr()
	adjBA = [set() for _ in range(n2)]
	adjCB = [set() for _ in range(n3)]
	adjDC = [set() for _ in range(n4)]

	def fillADJ(adj):
		m = int(input())
		for _ in range(m):
			(u, v) = readIntArr()
			u -= 1
			v -= 1
			adj[v].add(u)
	fillADJ(adjBA)
	fillADJ(adjCB)
	fillADJ(adjDC)
	minB = [inf for _ in range(n2)]
	minC = [inf for _ in range(n3)]
	minD = [inf for _ in range(n4)]

	def populateDP(costArr, adj, dp, nextCostArr):
		costSorted = [[cost, i] for (i, cost) in enumerate(costArr)]
		costSorted.sort(key=lambda x: x[0])
		for i in range(len(adj)):
			for (cost, j) in costSorted:
				if j not in adj[i]:
					dp[i] = cost
					break
		for (i, cost) in enumerate(nextCostArr):
			dp[i] += cost
	populateDP(a, adjBA, minB, b)
	populateDP(minB, adjCB, minC, c)
	populateDP(minC, adjDC, minD, d)
	ans = min(minD)
	if ans == inf:
		print(-1)
	else:
		print(ans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

class SparseTable:

	def __init__(self, A, ide_ele, f):
		self.n = len(A)
		self.f = f
		max_k = self.n.bit_length() - 1
		self.ide_ele = ide_ele
		self.table = [[ide_ele] * (max_k + 1) for i in range(self.n)]
		for i in range(self.n):
			self.table[i][0] = A[i]
		for k in range(1, max_k + 1):
			k2 = 1 << k - 1
			k3 = (1 << k) - 1
			for i in range(self.n - k3):
				self.table[i][k] = self.f(self.table[i][k - 1], self.table[i + k2][k - 1])

	def query(self, l, r):
		if l >= r:
			return self.ide_ele
		d = r - l
		if d == 1:
			return self.table[l][0]
		k = (d - 1).bit_length() - 1
		k2 = 1 << k
		return self.f(self.table[l][k], self.table[r - k2][k])
INF = 10 ** 18

def main():
	(n1, n2, n3, n4) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	D = list(map(int, input().split()))
	m1 = int(input())
	BA = [[] for i in range(n2)]
	for i in range(m1):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		BA[y].append(x)
	BA = [sorted(l) for l in BA]
	DPB = [INF] * n2
	A = SparseTable(A, INF, min)
	for i in range(n2):
		l = 0
		for r in BA[i]:
			DPB[i] = min(DPB[i], B[i] + A.query(l, r))
			l = r + 1
		DPB[i] = min(DPB[i], B[i] + A.query(l, A.n))
	m2 = int(input())
	CB = [[] for i in range(n3)]
	for i in range(m2):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		CB[y].append(x)
	CB = [sorted(l) for l in CB]
	DPC = [INF] * n3
	B = SparseTable(DPB, INF, min)
	for i in range(n3):
		l = 0
		for r in CB[i]:
			DPC[i] = min(DPC[i], C[i] + B.query(l, r))
			l = r + 1
		DPC[i] = min(DPC[i], C[i] + B.query(l, B.n))
	m3 = int(input())
	DC = [[] for i in range(n4)]
	for i in range(m3):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		DC[y].append(x)
	DC = [sorted(l) for l in DC]
	DPD = [INF] * n4
	C = SparseTable(DPC, INF, min)
	for i in range(n4):
		l = 0
		for r in DC[i]:
			DPD[i] = min(DPD[i], D[i] + C.query(l, r))
			l = r + 1
		DPD[i] = min(DPD[i], D[i] + C.query(l, C.n))
	ans = min(DPD)
	if ans >= INF:
		print(-1)
	else:
		print(ans)
main()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
tc = 1

def solve(a, b, c):
	ans = [INF for i in range(len(a))]
	g = [set() for i in range(len(a))]
	for (i, j) in c:
		g[i - 1].add(j - 1)
	bb = sorted([i for i in range(len(b))], key=lambda i: b[i])
	for i in range(len(a)):
		for k in bb:
			if k not in g[i]:
				ans[i] = a[i] + b[k]
				break
	return ans
for _ in range(tc):
	(n1, n2, n3, n4) = inp()
	a1 = inp()
	a2 = inp()
	a3 = inp()
	a4 = inp()
	b1 = [inp() for i in range(int(input()))]
	b2 = [inp() for i in range(int(input()))]
	b3 = [inp() for i in range(int(input()))]
	a3 = solve(a3, a4, b3)
	a2 = solve(a2, a3, b2)
	a1 = solve(a1, a2, b1)
	print(min(a1) if min(a1) < INF else -1)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 10 ** 9 + 7

def solve():
	(N1, N2, N3, N4) = getInts()
	(A, B, C, D) = (getInts(), getInts(), getInts(), getInts())
	A = [(a, i) for (i, a) in enumerate(A)]
	B = [(a, i) for (i, a) in enumerate(B)]
	C = [(a, i) for (i, a) in enumerate(C)]
	D = [(a, i) for (i, a) in enumerate(D)]
	A.sort()
	B.sort()
	C.sort()
	D.sort()
	m1 = dd(set)
	m2 = dd(set)
	m3 = dd(set)
	M1 = getInt()
	for m in range(M1):
		(x, y) = getInts()
		x -= 1
		y -= 1
		m1[y].add(x)
	M2 = getInt()
	for m in range(M2):
		(x, y) = getInts()
		x -= 1
		y -= 1
		m2[y].add(x)
	M3 = getInt()
	for m in range(M3):
		(x, y) = getInts()
		x -= 1
		y -= 1
		m3[y].add(x)
	NEW_A = []
	reach1 = set()
	for j in range(N2):
		idx = 0
		while idx < len(A) and A[idx][1] in m1[B[j][1]]:
			idx += 1
		if idx < N1:
			NEW_A.append((A[idx][0] + B[j][0], B[j][1]))
	if not NEW_A:
		return -1
	NEW_A.sort()
	NEW_B = []
	for j in range(N3):
		idx = 0
		while idx < len(NEW_A) and NEW_A[idx][1] in m2[C[j][1]]:
			idx += 1
		if idx < len(NEW_A):
			NEW_B.append((NEW_A[idx][0] + C[j][0], C[j][1]))
	if not NEW_B:
		return -1
	NEW_B.sort()
	ans = 10 ** 18
	for j in range(N4):
		idx = 0
		while idx < len(NEW_B) and NEW_B[idx][1] in m3[D[j][1]]:
			idx += 1
		if idx < len(NEW_B):
			ans = min(ans, NEW_B[idx][0] + D[j][0])
	return ans if ans < 10 ** 18 else -1
print(solve())


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = 10 ** 9
mod = 10 ** 9 + 7

def bucketsort(order, seq):
	buckets = [0] * (max(seq) + 1)
	for x in seq:
		buckets[x] += 1
	for i in range(len(buckets) - 1):
		buckets[i + 1] += buckets[i]
	new_order = [-1] * len(seq)
	for i in reversed(order):
		x = seq[i]
		idx = buckets[x] = buckets[x] - 1
		new_order[idx] = i
	return new_order

def ordersort(order, seq, reverse=False):
	bit = max(seq).bit_length() >> 1
	mask = (1 << bit) - 1
	order = bucketsort(order, [x & mask for x in seq])
	order = bucketsort(order, [x >> bit for x in seq])
	if reverse:
		order.reverse()
	return order

def long_ordersort(order, seq):
	order = ordersort(order, [int(i & 2147483647) for i in seq])
	return ordersort(order, [int(i >> 31) for i in seq])

def multikey_ordersort(order, *seqs, sort=ordersort):
	for i in reversed(range(len(seqs))):
		order = sort(order, seqs[i])
	return order

def do(a, b, map):
	ans = [inf] * len(b)
	ind = [i for i in range(len(a))]
	order = multikey_ordersort(range(len(a)), a, ind)
	new = []
	for i in order:
		new.append((a[i], ind[i]))
	for i in range(len(b)):
		for j in range(len(a)):
			if (new[j][1], i) in map:
				continue
			ans[i] = b[i] + new[j][0]
			break
	return ans

def solve(case):
	(n1, n2, n3, n4) = sep()
	a = lis()
	b = lis()
	c = lis()
	d = lis()
	map1 = {}
	for i in range(int(inp())):
		(x, y) = sep()
		x -= 1
		y -= 1
		map1[x, y] = 1
	map2 = {}
	for i in range(int(inp())):
		(x, y) = sep()
		x -= 1
		y -= 1
		map2[x, y] = 1
	map3 = {}
	for i in range(int(inp())):
		(x, y) = sep()
		x -= 1
		y -= 1
		map3[x, y] = 1
	dp = a
	dp = do(dp, b, map1)
	dp = do(dp, c, map2)
	dp = do(dp, d, map3)
	ans = min(dp)
	if ans >= inf:
		print(-1)
	else:
		print(ans)
testcase(1)


import sys
input = lambda : sys.stdin.readline().rstrip()

def ttt():
	(a, b) = map(int, input().split())
	return (a - 1 << 18) + b - 1
(n1, n2, n3, n4) = map(int, input().split())
A = [(i, int(a)) for (i, a) in enumerate(input().split())]
B = [(i, int(a)) for (i, a) in enumerate(input().split())]
C = [(i, int(a)) for (i, a) in enumerate(input().split())]
D = [(i, int(a)) for (i, a) in enumerate(input().split())]
X = {ttt() for _ in range(int(input()))}
Y = {ttt() for _ in range(int(input()))}
Z = {ttt() for _ in range(int(input()))}

def calc(T, prev, NG):
	prev = sorted(prev, key=lambda x: x[1])
	for _ in range(len(T)):
		(i, a) = T[_]
		for (j, b) in prev:
			if (j << 18) + i in NG:
				continue
			T[_] = (i, a + b)
			break
		else:
			T[_] = (i, 10 ** 18)
calc(B, A, X)
calc(C, B, Y)
calc(D, C, Z)
mi = min((z for (i, z) in D))
print(mi if mi < 10 ** 15 else -1)


import sys
from collections import defaultdict
from io import BytesIO, IOBase

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 4096

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def solve_e():
	n = get_ints()
	costs = [get_ints() for course in range(4)]
	costs = [[(x, j) for (j, x) in enumerate(cost)] for cost in costs]
	m = []
	mismatch_graph = [defaultdict(set) for _ in range(3)]
	for course_trans in range(3):
		m.append(get_int())
		for mismatch in range(m[-1]):
			(a, b) = get_ints()
			mismatch_graph[course_trans][b - 1].add(a - 1)
	dp = [sorted(costs[0])]
	for j in range(3):
		tmp = []
		for l in range(n[j + 1]):
			k = 0
			while k < n[j]:
				if costs[j + 1][l][-1] in mismatch_graph[j] and dp[-1][k][-1] in mismatch_graph[j][costs[j + 1][l][-1]]:
					k += 1
				else:
					break
			if k == n[j]:
				tmp.append((float('inf'), costs[j + 1][l][-1]))
			else:
				tmp.append((costs[j + 1][l][0] + dp[-1][k][0], costs[j + 1][l][-1]))
		dp.append(sorted(tmp))
	if min(dp[-1])[0] == float('inf'):
		return -1
	else:
		return min(dp[-1])[0]
print(solve_e())


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
INF = 10 ** 18

def main():
	(n1, n2, n3, n4) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	D = list(map(int, input().split()))
	A = [(e, i) for (i, e) in enumerate(A)]
	A.sort()
	m1 = int(input())
	XY1 = [set() for i in range(n2)]
	for i in range(m1):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		XY1[y].add(x)
	dpb = [INF] * n2
	for (i, b) in enumerate(B):
		for (a, j) in A:
			if j in XY1[i]:
				continue
			dpb[i] = b + a
			break
	m2 = int(input())
	XY2 = [set() for i in range(n3)]
	for i in range(m2):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		XY2[y].add(x)
	dpb = [(e, i) for (i, e) in enumerate(dpb)]
	dpb.sort()
	dpc = [INF] * n3
	for (i, c) in enumerate(C):
		for (b, j) in dpb:
			if j in XY2[i]:
				continue
			dpc[i] = c + b
			break
	m3 = int(input())
	XY3 = [set() for i in range(n4)]
	for i in range(m3):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		XY3[y].add(x)
	dpc = [(e, i) for (i, e) in enumerate(dpc)]
	dpc.sort()
	dpd = [INF] * n4
	for (i, d) in enumerate(D):
		for (c, j) in dpc:
			if j in XY3[i]:
				continue
			dpd[i] = d + c
			break
	ans = min(dpd)
	if ans < INF:
		print(ans)
	else:
		print(-1)
main()


from sys import stdin, stdout
(n1, n2, n3, n4) = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
b = [int(x) for x in stdin.readline().split()]
c = [int(x) for x in stdin.readline().split()]
d = [int(x) for x in stdin.readline().split()]
a = [[i, a[i]] for i in range(n1)]
a.sort(key=lambda x: x[1])
m1 = int(stdin.readline())
bad_match = [set() for _ in range(n2)]
for _ in range(m1):
	(X, Y) = [int(x) for x in stdin.readline().split()]
	bad_match[Y - 1].add(X - 1)
B = [[i, 400000001] for i in range(n2)]
for Y in range(n2):
	for candidate in a:
		if not candidate[0] in bad_match[Y]:
			B[Y][1] = candidate[1] + b[Y]
			break
B.sort(key=lambda x: x[1])
m2 = int(stdin.readline())
bad_match = [set() for _ in range(n3)]
for _ in range(m2):
	(X, Y) = [int(x) for x in stdin.readline().split()]
	bad_match[Y - 1].add(X - 1)
C = [[i, 400000001] for i in range(n3)]
for Y in range(n3):
	for candidate in B:
		if not candidate[0] in bad_match[Y]:
			C[Y][1] = candidate[1] + c[Y]
			break
C.sort(key=lambda x: x[1])
m3 = int(stdin.readline())
bad_match = [set() for _ in range(n4)]
for _ in range(m3):
	(X, Y) = [int(x) for x in stdin.readline().split()]
	bad_match[Y - 1].add(X - 1)
D = [400000001] * n4
for Y in range(n4):
	for candidate in C:
		if not candidate[0] in bad_match[Y]:
			D[Y] = candidate[1] + d[Y]
			break
minimum = min(D)
if minimum >= 400000001:
	stdout.write(str(-1) + '\n')
else:
	stdout.write(str(minimum) + '\n')


import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
	(n1, n2, n3, n4) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	m1 = int(input())
	pair1 = [list(map(int, input().split())) for _ in range(m1)]
	m2 = int(input())
	pair2 = [list(map(int, input().split())) for _ in range(m2)]
	m3 = int(input())
	pair3 = [list(map(int, input().split())) for _ in range(m3)]
	a = list(enumerate(a))
	b = list(enumerate(b))
	c = list(enumerate(c))
	d = list(enumerate(d))

	def calc(prev, now, pair):
		n = len(now)
		prev = sorted(prev, key=lambda x: x[1])
		pair_dict = defaultdict(lambda : set())
		for p in pair:
			(x, y) = p
			pair_dict[y].add(x)
		cost = [float('inf')] * n
		for i in range(1, n + 1):
			j = 0
			while True:
				if j > len(prev) - 1:
					break
				if not prev[j][0] + 1 in pair_dict[i]:
					cost[i - 1] = now[i - 1][1] + prev[j][1]
					break
				else:
					j += 1
		cost = list(enumerate(cost))
		return cost
	cost1 = calc(a, b, pair1)
	cost2 = calc(cost1, c, pair2)
	cost3 = calc(cost2, d, pair3)
	cost3 = sorted(cost3, key=lambda x: x[1])
	ans = cost3[0][1]
	if ans == float('inf'):
		ans = -1
	print(ans)
main()


import os
import sys
from io import BytesIO, IOBase
import heapq

def fv(A, B, rA):
	mA = [[B[i], i] for i in range(len(B))]
	mA.sort()
	for i in range(len(A)):
		v = rA[i]
		flag = 0
		G = {}
		for j in v:
			G[j] = 1
		for j in range(len(B)):
			if mA[j][1] in G:
				continue
			else:
				A[i] = A[i] + mA[j][0]
				flag = 1
				break
		if flag == 0:
			A[i] = float('inf')

def main():
	(n1, n2, n3, n4) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	D = list(map(int, input().split()))
	rA = [[] for i in range(n1)]
	rB = [[] for i in range(n2)]
	rC = [[] for i in range(n3)]
	m1 = int(input())
	for i in range(m1):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		rA[x].append(y)
	m2 = int(input())
	for i in range(m2):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		rB[x].append(y)
	m3 = int(input())
	for i in range(m3):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		rC[x].append(y)
	fv(C, D, rC)
	fv(B, C, rB)
	fv(A, B, rA)
	v = min(A)
	if v == float('inf'):
		print(-1)
	else:
		print(v)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
INF = int(1000000000.0)
(n1, n2, n3, n4) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
postx = [[] for _ in range(n2)]
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	postx[y - 1].append(x - 1)
prei = []
for i in range(n1):
	prei.append((i, a[i]))
prei.sort(key=lambda x: x[1])
for i in range(n2):
	if not postx[i]:
		b[i] += prei[0][1]
	else:
		if len(postx[i]) == n1:
			b[i] = INF
			continue
		for (index, cost) in prei:
			if index in postx[i]:
				continue
			else:
				b[i] += cost
				break
postx = [[] for _ in range(n3)]
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	postx[y - 1].append(x - 1)
prei = []
for i in range(n2):
	prei.append((i, b[i]))
prei.sort(key=lambda x: x[1])
for i in range(n3):
	if not postx[i]:
		c[i] += prei[0][1]
	else:
		if len(postx[i]) == n2:
			c[i] = INF
			continue
		for (index, cost) in prei:
			if index in postx[i]:
				continue
			else:
				c[i] += cost
				break
postx = [[] for _ in range(n4)]
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	postx[y - 1].append(x - 1)
prei = []
for i in range(n3):
	prei.append((i, c[i]))
prei.sort(key=lambda x: x[1])
for i in range(n4):
	if not postx[i]:
		d[i] += prei[0][1]
	else:
		if len(postx[i]) == n3:
			d[i] = INF
			continue
		for (index, cost) in prei:
			if index in postx[i]:
				continue
			else:
				d[i] += cost
				break
if min(d) >= INF:
	print(-1)
else:
	print(min(d))


import sys, os, io
input = sys.stdin.readline
(n1, n2, n3, n4) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
from collections import defaultdict
m1 = int(input())
dic1 = defaultdict(lambda : 0)
for i in range(m1):
	(x, y) = map(int, input().split())
	dic1[x - 1, y - 1] = 1
m2 = int(input())
dic2 = defaultdict(lambda : 0)
for i in range(m2):
	(x, y) = map(int, input().split())
	dic2[x - 1, y - 1] = 1
m3 = int(input())
dic3 = defaultdict(lambda : 0)
for i in range(m3):
	(x, y) = map(int, input().split())
	dic3[x - 1, y - 1] = 1
lis1 = []
lis2 = []
lis3 = []
lis4 = []
for (i, d) in enumerate(D):
	lis4.append((d, i))
lis4.sort()
for (j, c) in enumerate(C):
	for (d, i) in lis4:
		if dic3[j, i] == 0:
			lis3.append((c + d, j))
			break
lis3.sort()
for (k, b) in enumerate(B):
	for (c, j) in lis3:
		if dic2[k, j] == 0:
			lis2.append((b + c, k))
			break
lis2.sort()
for (l, a) in enumerate(A):
	for (b, k) in lis2:
		if dic1[l, k] == 0:
			lis1.append((a + b, l))
			break
if len(lis1):
	print(min(lis1)[0])
else:
	print(-1)


INF = 10 ** 9
(n1, n2, n3, n4) = map(int, input().split())
solution_a = [(int(x), i) for (i, x) in enumerate(input().split())]
(*b,) = map(int, input().split())
(*c,) = map(int, input().split())
(*d,) = map(int, input().split())
solution_a.sort()
b_a_denies = {}
for _ in ' ' * int(input()):
	(x, y) = map(int, input().split())
	b_a_denies.setdefault(y - 1, set())
	b_a_denies[y - 1].add(x - 1)
for i in range(n2):
	denied = b_a_denies.get(i, set())
	for (cost_a, idx) in solution_a:
		if idx not in denied:
			b[i] += cost_a
			break
	else:
		b[i] = INF
del solution_a, b_a_denies
solution_b = [(b[i], i) for i in range(n2)]
solution_b.sort()
c_b_denies = {}
for _ in ' ' * int(input()):
	(x, y) = map(int, input().split())
	c_b_denies.setdefault(y - 1, set())
	c_b_denies[y - 1].add(x - 1)
for i in range(n3):
	denied = c_b_denies.get(i, set())
	for (cost_b, idx) in solution_b:
		if idx not in denied:
			c[i] += cost_b
			break
	else:
		c[i] = INF
del solution_b, c_b_denies
solution_c = [(c[i], i) for i in range(n3)]
solution_c.sort()
d_c_denies = {}
for _ in ' ' * int(input()):
	(x, y) = map(int, input().split())
	d_c_denies.setdefault(y - 1, set())
	d_c_denies[y - 1].add(x - 1)
for i in range(n4):
	denied = d_c_denies.get(i, set())
	for (cost_c, idx) in solution_c:
		if idx not in denied:
			d[i] += cost_c
			break
	else:
		d[i] = INF
print(min(d) if min(d) < INF else -1)


import sys
from math import sqrt
input = sys.stdin.readline

def construct(arr, n):
	block_len = int(sqrt(n))
	blocks = []
	for i in range(0, n, block_len):
		curr_min = 10 ** 9
		for j in range(block_len):
			if i + j >= n:
				break
			curr_min = min(curr_min, arr[i + j])
		blocks.append(curr_min)
	return (blocks, block_len)

def find_min(l, r, arr, blocks, block_len):
	if l > r:
		return 10 ** 9
	ans = 10 ** 9
	if l % block_len == 0:
		bl = l // block_len
	else:
		bl = l // block_len + 1
		for i in range(l, min(r + 1, bl * block_len)):
			ans = min(ans, arr[i])
	if r % block_len == block_len - 1:
		br = r // block_len + 1
	else:
		br = r // block_len
		if bl == br:
			return ans
		for i in range(max(l, br * block_len), r + 1):
			ans = min(ans, arr[i])
	for i in range(bl, br):
		ans = min(ans, blocks[i])
	return ans

def main():
	ns = tuple(map(int, input().split()))
	prices = []
	for _ in range(4):
		curr = tuple(map(int, input().split()))
		prices.append(curr)
	non_matching = [None]
	for _ in range(3):
		m = int(input())
		curr = {}
		for _ in range(m):
			pair = list(map(int, input().split()))
			pair[0] -= 1
			pair[1] -= 1
			if pair[1] not in curr:
				curr[pair[1]] = []
			curr[pair[1]].append(pair[0])
		non_matching.append(curr)
	dp = [prices[0], [0] * ns[1], [0] * ns[2], [0] * ns[3]]
	for i in range(1, 4):
		prev_n = ns[i - 1]
		prev_dp = dp[i - 1]
		(blocks, block_len) = construct(prev_dp, prev_n)
		for j in range(ns[i]):
			curr_nm = non_matching[i].get(j)
			if not curr_nm:
				dp[i][j] = find_min(0, prev_n - 1, prev_dp, blocks, block_len) + prices[i][j]
			else:
				l = 0
				ans = 10 ** 9
				for nm in sorted(curr_nm):
					curr_min = find_min(l, nm - 1, prev_dp, blocks, block_len)
					ans = min(ans, curr_min)
					l = nm + 1
				curr_min = find_min(l, prev_n - 1, prev_dp, blocks, block_len)
				ans = min(ans, curr_min)
				dp[i][j] = ans + prices[i][j]
	ans = 10 ** 9
	for val in dp[3]:
		ans = min(val, ans)
	if ans >= 10 ** 9:
		print(-1)
	else:
		print(ans)

def main_wo_decomp():
	ns = tuple(map(int, input().split()))
	prices = [tuple(map(int, input().split())) for _ in range(4)]
	dp = sorted([(prices[0][i], i) for i in range(ns[0])])
	INF = 10 ** 9
	for k in range(3):
		m = int(input())
		non_matching = {}
		for _ in range(m):
			pair = list(map(int, input().split()))
			pair[0] -= 1
			pair[1] -= 1
			if pair[1] not in non_matching:
				non_matching[pair[1]] = set()
			non_matching[pair[1]].add(pair[0])
		n = ns[k + 1]
		ndp = [INF] * n
		for i in range(n):
			curr_nm = non_matching.get(i, [])
			for tpl in dp:
				if tpl[1] not in curr_nm:
					ndp[i] = tpl[0] + prices[k + 1][i]
					break
		dp = sorted([(ndp[i], i) for i in range(n)])
	if dp[0][0] < INF:
		print(dp[0][0])
	else:
		print(-1)

def tests():
	arr = [8, -2, -30, 1, 9, 12, 8, 3, -1, 16, 0, -9, 12, 8, 3, 9, 12, 8, 3]
	n = len(arr)
	(blocks, block_len) = construct(arr, n)
	print(find_min(1, 1, arr, blocks, block_len))
main_wo_decomp()


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf
n = lmp()
A = lmp()
B = lmp()
C = lmp()
D = lmp()
a = [(A[i], i + 1) for i in range(n[0])]
b = [(B[i], i + 1) for i in range(n[1])]
c = [(C[i], i + 1) for i in range(n[2])]
d = [(D[i], i + 1) for i in range(n[3])]
m1 = dd(set)
for _ in range(iinp()):
	(x, y) = mp()
	m1[y].add(x)
m2 = set()
for _ in range(iinp()):
	(x, y) = mp()
	m2.add((x, y))
m3 = dd(set)
for _ in range(iinp()):
	(x, y) = mp()
	m3[x].add(y)
a.sort()
b.sort()
c.sort()
d.sort()
min12 = []
for i in range(n[1]):
	for j in range(n[0]):
		if a[j][1] not in m1[b[i][1]]:
			min12.append((a[j][0] + b[i][0], b[i][1], a[j][1]))
			break
min34 = []
for i in range(n[2]):
	for j in range(n[3]):
		if d[j][1] not in m3[c[i][1]]:
			min34.append((d[j][0] + c[i][0], c[i][1], d[j][1]))
			break
min12.sort()
min34.sort()
ans = inf
for i in range(len(min12) + len(min34) - 1):
	dd = inf
	if i < len(min12):
		z1 = 0
	else:
		z1 = i - len(min12) + 1
	if i < len(min34):
		z2 = 0
	else:
		z2 = i - len(min34) + 1
	for j in range(z1, i - z2 + 1):
		if (min12[j][1], min34[i - j][1]) not in m2:
			dd = min(dd, min12[j][0] + min34[i - j][0])
	if dd != inf:
		ans = dd
		break
if ans == inf:
	print(-1)
else:
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict

def solution(n1, n2, n3, n4, a, b, c, d, m1, m2, m3, edges_m1, edges_m2, edges_m3):
	backward_adj = []
	n = [n1, n2, n3, n4]
	costs_n = [a, b, c, d]
	m = [m1, m2, m3]
	edges = [edges_m1, edges_m2, edges_m3]
	cols_vertices = [[] for _ in range(4)]
	for (pos_col, col) in enumerate(cols_vertices):
		cols_vertices[pos_col] = [[costs_n[pos_col][i], i] for i in range(n[pos_col])]
	backward_adj.append(defaultdict(set))
	backward_adj.append(defaultdict(set))
	backward_adj.append(defaultdict(set))
	for step in [0, 1, 2]:
		edges_step = edges[step]
		adj = backward_adj[step]
		for [u, v] in edges_step:
			adj[v - 1].add(u - 1)
	for (pos_col, col) in enumerate(cols_vertices[0:-1]):
		col.sort()
		prev_col = cols_vertices[pos_col]
		next_col = cols_vertices[pos_col + 1]
		adj = backward_adj[pos_col]
		for (pos_next, [cost_v, v]) in enumerate(next_col):
			found = False
			for (pos_prev, [cost_u, u]) in enumerate(prev_col):
				if u not in adj[v]:
					next_col[pos_next] = [cost_u + cost_v, v]
					found = True
					break
			if found is False:
				next_col[pos_next] = [10 ** 10, v]
	sol_distance = min([cols_vertices[3][i][0] for i in range(len(cols_vertices[-1]))])
	if sol_distance >= 10 ** 10:
		print(-1)
	else:
		print(sol_distance)
(n1, n2, n3, n4) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
m1 = int(input())
edges_m1 = [list(map(int, input().split())) for _ in range(m1)]
m2 = int(input())
edges_m2 = [list(map(int, input().split())) for _ in range(m2)]
m3 = int(input())
edges_m3 = [list(map(int, input().split())) for _ in range(m3)]
solution(n1, n2, n3, n4, a, b, c, d, m1, m2, m3, edges_m1, edges_m2, edges_m3)


from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fun(n1, n2, a1, b, d1):
	new = []
	st = []
	ind = 0
	for j in range(n2):
		st.append([b[j], j + 1])
	while st != []:
		res1 = []
		for j in st:
			if d1[j[1], a1[ind][1]]:
				new.append([j[0] + a1[ind][0], j[1]])
			else:
				res1.append([j[0], j[1]])
		st = res1
		ind += 1
		if ind == n1:
			break
	return sorted(new)
(n1, n2, n3, n4) = map(int, input().split())
a = list(map(int, input().split()))
a1 = []
for j in range(n1):
	a1.append([a[j], j + 1])
a1.sort()
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
m1 = int(input())
d1 = defaultdict(lambda : 1)
for j in range(m1):
	(u, v) = map(int, input().split())
	d1[v, u] = 0
res = fun(n1, n2, a1, b, d1)
if res == []:
	print(-1)
else:
	m2 = int(input())
	d1 = defaultdict(lambda : 1)
	for j in range(m2):
		(u, v) = map(int, input().split())
		d1[v, u] = 0
	res2 = fun(len(res), n3, res, c, d1)
	if res2 == []:
		print(-1)
	else:
		m3 = int(input())
		d1 = defaultdict(lambda : 1)
		for j in range(m3):
			(u, v) = map(int, input().split())
			d1[v, u] = 0
		res3 = fun(len(res2), n4, res2, d, d1)
		if res3 == []:
			print(-1)
		else:
			print(res3[0][0])


from sys import *
input = stdin.readline

def nxt(l, s):
	for (i, j) in l:
		if j not in s:
			return i
	return 1 << 30
from collections import defaultdict
(n1, n2, n3, n4) = map(int, input().split())
a = sorted(([j, i + 1] for (i, j) in enumerate(map(int, input().split()))))
b = sorted(([j, i + 1] for (i, j) in enumerate(map(int, input().split()))))
c = sorted(([j, i + 1] for (i, j) in enumerate(map(int, input().split()))))
d = sorted(([j, i + 1] for (i, j) in enumerate(map(int, input().split()))))
(m1, m2, m3) = (defaultdict(set), defaultdict(set), defaultdict(set))
for i in range(int(input())):
	(ai, bi) = map(int, input().split())
	m1[bi].add(ai)
for i in range(n2):
	b[i][0] += nxt(a, m1[b[i][1]])
for i in range(int(input())):
	(ai, bi) = map(int, input().split())
	m2[ai].add(bi)
for i in range(int(input())):
	(ai, bi) = map(int, input().split())
	m3[ai].add(bi)
for i in range(n3):
	c[i][0] += nxt(d, m3[c[i][1]])
b.sort()
c.sort()
for i in range(n2):
	b[i][0] += nxt(c, m2[b[i][1]])
print(min(b)[0] if min(b)[0] < 1 << 30 else -1)


import sys
input = sys.stdin.readline
INF = 10 ** 12

def update(al0, al1, gl01):
	ail0 = [(al0[i], i) for i in range(len(al0))]
	ail0.sort(key=lambda x: x[0])
	res = [INF] * len(al1)
	rems = list(range(len(al1)))
	for (a, i) in ail0:
		new_rems = []
		for i1 in rems:
			if i1 in gl01[i]:
				new_rems.append(i1)
			else:
				res[i1] = a + al1[i1]
		rems = new_rems[:]
	for i in range(len(al1)):
		al1[i] = res[i]
nl = list(map(int, input().split()))
al0 = list(map(int, input().split()))
al1 = list(map(int, input().split()))
al2 = list(map(int, input().split()))
al3 = list(map(int, input().split()))
g01 = [set() for _ in range(nl[0])]
g12 = [set() for _ in range(nl[1])]
g23 = [set() for _ in range(nl[2])]
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	g01[a - 1].add(b - 1)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	g12[a - 1].add(b - 1)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	g23[a - 1].add(b - 1)
update(al0, al1, g01)
update(al1, al2, g12)
update(al2, al3, g23)
ans = min(al3)
if ans >= INF:
	ans = -1
print(ans)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def G(n):
	return [[] for i in range(n)]

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def lcm(a, b):
	return a * b // gcd(a, b)

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	if len(g[r]) == 1 and p != -1:
		yield None
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None

def f(x, y, r):
	a = len(x)
	b = len(y)
	ans = AI(a, [inf, 0])
	for i in range(a):
		for j in range(b):
			if (x[i][1], y[j][1]) not in r:
				ans[i] = [x[i][0] + y[j][0], x[i][1]]
				break
	return ans
t = 1
for i in range(t):
	(n1, n2, n3, n4) = RL()
	a = RLL()
	a = [(x, i) for (i, x) in enumerate(a)]
	b = RLL()
	b = [(x, i) for (i, x) in enumerate(b)]
	c = RLL()
	c = [(x, i) for (i, x) in enumerate(c)]
	d = RLL()
	d = [(x, i) for (i, x) in enumerate(d)]
	m = N()
	res = set()
	for i in range(m):
		(x, y) = RLL()
		x -= 1
		y -= 1
		res.add((x, y))
	m2 = N()
	res2 = set()
	for i in range(m2):
		(x, y) = RLL()
		x -= 1
		y -= 1
		res2.add((x, y))
	m3 = N()
	res3 = set()
	for i in range(m3):
		(x, y) = RLL()
		x -= 1
		y -= 1
		res3.add((x, y))
	c.sort()
	d.sort()
	c = f(c, d, res3)
	c.sort()
	b.sort()
	b = f(b, c, res2)
	b.sort()
	a = f(a, b, res)
	ans = min((a[i][0] for i in range(n1)))
	if ans == inf:
		ans = -1
	print(ans)


import sys
input = sys.stdin.readline

def encode(x, y):
	return (x - 1 << 18) + y
(n1, n2, n3, n4) = map(int, input().split())
a = [(int(item), i) for (i, item) in enumerate(input().split())]
b = [(int(item), i) for (i, item) in enumerate(input().split())]
c = [(int(item), i) for (i, item) in enumerate(input().split())]
d = [(int(item), i) for (i, item) in enumerate(input().split())]
a.sort()
b.sort()
c.sort()
d.sort()
m1 = int(input())
m1s = set()
for _ in range(m1):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	m1s.add(encode(x, y))
m2 = int(input())
m2s = set()
for _ in range(m2):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	m2s.add(encode(x, y))
m3 = int(input())
m3s = set()
for _ in range(m3):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	m3s.add(encode(x, y))
ab = []
for (bb, ib) in b:
	for (aa, ia) in a:
		if encode(ia, ib) in m1s:
			continue
		ab.append((aa + bb, ib))
		break
if not ab:
	print(-1)
	exit()
ab.sort()
bc = []
for (cc, ic) in c:
	for (aabb, ib) in ab:
		if encode(ib, ic) in m2s:
			continue
		bc.append((aabb + cc, ic))
		break
if not bc:
	print(-1)
	exit()
bc.sort()
cd = []
ans = 10 ** 10
for (dd, idd) in d:
	for (bbcc, ic) in bc:
		if encode(ic, idd) in m3s:
			continue
		if bbcc + dd < ans:
			ans = bbcc + dd
		break
if ans == 10 ** 10:
	print(-1)
else:
	print(ans)


import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda : map(int, input().split())
inf = 1000000000.0
(n1, n2, n3, n4) = read()
a = list(read())
b = list(read())
c = list(read())
d = list(read())
m1 = int(input())
l1 = []
for _ in range(m1):
	l1 += list(read())
m2 = int(input())
l2 = []
for _ in range(m2):
	l2 += list(read())
m3 = int(input())
l3 = []
for _ in range(m3):
	l3 += list(read())
l = [0] * n3
for i in range(len(l3) // 2):
	(x, y) = (l3[-2 * i - 2] - 1, l3[-2 * i - 1] - 1)
	if l[x]:
		l[x].append(d[y])
	else:
		l[x] = [d[y]]
l3 = 0
sd = sorted(d)
for i in range(n3):
	if l[i]:
		l[i].sort(reverse=True)
		for j in range(n4):
			if not l[i]:
				break
			if l[i][-1] > sd[j]:
				break
			else:
				l[i].pop()
		else:
			j = -1
		if j < 0 or sd[j] == inf:
			c[i] = inf
		else:
			c[i] += sd[j]
	else:
		c[i] += sd[0]
l = [0] * n2
for i in range(len(l2) // 2):
	(x, y) = (l2[-2 * i - 2] - 1, l2[-2 * i - 1] - 1)
	if l[x]:
		l[x].append(c[y])
	else:
		l[x] = [c[y]]
l2 = 0
sc = sorted(c)
for i in range(n2):
	if l[i]:
		l[i].sort(reverse=True)
		for j in range(n3):
			if not l[i]:
				break
			if l[i][-1] > sc[j]:
				break
			else:
				l[i].pop()
		else:
			j = -1
		if j < 0 or sc[j] == inf:
			b[i] = inf
		else:
			b[i] += sc[j]
	else:
		b[i] += sc[0]
l = [0] * n1
for i in range(len(l1) // 2):
	(x, y) = (l1[-2 * i - 2] - 1, l1[-2 * i - 1] - 1)
	if l[x]:
		l[x].append(b[y])
	else:
		l[x] = [b[y]]
l1 = 0
sb = sorted(b)
for i in range(n1):
	if l[i]:
		l[i].sort(reverse=True)
		for j in range(n2):
			if not l[i]:
				break
			if l[i][-1] > sb[j]:
				break
			else:
				l[i].pop()
		else:
			j = -1
		if j < 0 or sb[j] == inf:
			a[i] = inf
		else:
			a[i] += sb[j]
	else:
		a[i] += sb[0]
v = min(a)
if v >= inf:
	print(-1)
else:
	print(v)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = 1
r = 1
while r <= T:
	(n1, n2, n3, n4) = map(int, input().split())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr3 = list(map(int, input().split()))
	arr4 = list(map(int, input().split()))
	no12 = {}
	d = int(input())
	for i in range(d):
		(index1, index2) = map(int, input().split())
		no12[index1 - 1, index2 - 1] = 1
	no23 = {}
	d = int(input())
	for i in range(d):
		(index2, index3) = map(int, input().split())
		no23[index2 - 1, index3 - 1] = 1
	no34 = {}
	d = int(input())
	for i in range(d):
		(index3, index4) = map(int, input().split())
		no34[index3 - 1, index4 - 1] = 1
	sortarr1 = []
	for i in range(n1):
		sortarr1.append([arr1[i], i])
	sortarr1 = sorted(sortarr1)
	dp2 = [0] * n2
	for i in range(n2):
		j = 0
		while j < n1 and (sortarr1[j][1], i) in no12:
			j += 1
		if j < n1:
			dp2[i] = sortarr1[j][0] + arr2[i]
		else:
			dp2[i] = float('inf')
	sortarr2 = []
	for i in range(n2):
		sortarr2.append([dp2[i], i])
	sortarr2 = sorted(sortarr2)
	dp3 = [0] * n3
	for i in range(n3):
		j = 0
		while j < n2 and (sortarr2[j][1], i) in no23:
			j += 1
		if j < n2 and sortarr2[j][0] < float('inf'):
			dp3[i] = sortarr2[j][0] + arr3[i]
		else:
			dp3[i] = float('inf')
	sortarr3 = []
	for i in range(n3):
		sortarr3.append([dp3[i], i])
	sortarr3 = sorted(sortarr3)
	dp4 = [0] * n4
	for i in range(n4):
		j = 0
		while j < n3 and (sortarr3[j][1], i) in no34:
			j += 1
		if j < n3 and sortarr3[j][0] < float('inf'):
			dp4[i] = sortarr3[j][0] + arr4[i]
		else:
			dp4[i] = float('inf')
	if min(dp4) < float('inf'):
		print(min(dp4))
	else:
		print(-1)
	r += 1


class SegmentTree:

	def __init__(self, array, f=lambda x, y: x + y, inf=0):
		self.height = (len(array) - 1).bit_length()
		self.n = 2 ** self.height
		self.id = inf
		self.tree = [self.id] * (2 * self.n)
		self.f = f
		for i in range(len(array)):
			self.tree[self.n + i] = array[i]
		for i in range(self.n - 1, 0, -1):
			self.tree[i] = self.f(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, i, x):
		i += self.n
		self.tree[i] = x
		while i > 1:
			i //= 2
			self.tree[i] = self.f(self.tree[2 * i], self.tree[2 * i + 1])

	def query(self, l, r):
		l += self.n
		r += self.n
		(lf, rf) = (self.id, self.id)
		while l < r:
			if l & 1:
				lf = self.f(lf, self.tree[l])
				l += 1
			if r & 1:
				r -= 1
				rf = self.f(self.tree[r], rf)
			l //= 2
			r //= 2
		return self.f(lf, rf)

	def BinarySearch(self, l, r, f):
		if not f(self.query(l, r)):
			return r + 1
		l += self.n
		r += self.n
		while True:
			if f(self.tree[l]):
				if l >= self.n:
					return l - self.n + 1
				else:
					l *= 2
			elif l % 2 == 0:
				l += 1
			else:
				l = l // 2 + 1

	def display(self):
		for i in range(self.n, self.n * 2):
			print(self.tree[i], end=' ')
			while i % 2 == 0:
				i //= 2
				print(self.tree[i], end=' ')
			print()
from collections import defaultdict
import sys
input = sys.stdin.readline
(n1, n2, n3, n4) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
m1 = int(input())
e = [[] for _ in range(n2)]
f = [[] for _ in range(n3)]
g = [[] for _ in range(n4)]
for i in range(m1):
	(x, y) = map(int, input().split())
	e[y - 1].append(x - 1)
m2 = int(input())
for i in range(m2):
	(x, y) = map(int, input().split())
	f[y - 1].append(x - 1)
m3 = int(input())
for i in range(m3):
	(x, y) = map(int, input().split())
	g[y - 1].append(x - 1)
INF = 10 ** 10
S1 = SegmentTree(a, min, INF)
for i in range(n2):
	for j in e[i]:
		S1.update(j, INF)
	b[i] += S1.tree[1]
	for j in e[i]:
		S1.update(j, a[j])
S2 = SegmentTree(b, min, INF)
for i in range(n3):
	for j in f[i]:
		S2.update(j, INF)
	c[i] += S2.tree[1]
	for j in f[i]:
		S2.update(j, b[j])
S3 = SegmentTree(c, min, INF)
for i in range(n4):
	for j in g[i]:
		S3.update(j, INF)
	d[i] += S3.tree[1]
	for j in g[i]:
		S3.update(j, c[j])
ans = min(d)
print(-1 if ans >= INF else ans)


from __future__ import division, print_function
import os
import sys
import itertools
from collections import defaultdict
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	INF = float('inf')
	n = list(map(int, input().split()))
	arr = [[int(ai) for ai in input().split()], [int(bi) for bi in input().split()], [int(ci) for ci in input().split()], [int(di) for di in input().split()]]
	for i in range(3):
		p = defaultdict(list)
		m = int(input())
		for _ in range(m):
			(x, y) = map(int, input().split())
			p[y - 1].append(x - 1)
		order = sorted(range(n[i]), key=arr[i].__getitem__)
		for j in range(n[i + 1]):
			if n[i] == len(p[j]):
				arr[i + 1][j] = INF
				continue
			p[j].sort()
			p[j].sort(key=arr[i].__getitem__)
			for (k, l) in itertools.zip_longest(order, p[j]):
				if k != l:
					arr[i + 1][j] += arr[i][k]
					break
	sol = min(arr[-1])
	print(-1 if sol == INF else sol)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout

def cheap_dinner(n1, n2, n3, n4, a_a, b_a, c_a, d_a, dic_a, dic_b, dic_c):
	INF = 10 ** 10
	d_a.sort(key=lambda x: x[1])
	for ci in range(1, n3 + 1):
		found = False
		for d in d_a:
			if ci not in dic_c or d[0] + 1 not in dic_c[ci]:
				c_a[ci - 1][1] += d[1]
				found = True
				break
		if not found:
			c_a[ci - 1][1] = INF
	c_a.sort(key=lambda x: x[1])
	for bi in range(1, n2 + 1):
		found = False
		for c in c_a:
			if c[1] == INF:
				break
			if bi not in dic_b or c[0] + 1 not in dic_b[bi]:
				b_a[bi - 1][1] += c[1]
				found = True
				break
		if not found:
			b_a[bi - 1][1] = INF
	b_a.sort(key=lambda x: x[1])
	r = INF
	for ai in range(1, n1 + 1):
		for b in b_a:
			if b[1] == INF:
				break
			if ai not in dic_a or b[0] + 1 not in dic_a[ai]:
				r = min(r, a_a[ai - 1][1] + b[1])
				break
	if r == INF:
		return -1
	else:
		return r
(n1, n2, n3, n4) = map(int, stdin.readline().split())
a_a = list(map(int, stdin.readline().split()))
b_a = list(map(int, stdin.readline().split()))
c_a = list(map(int, stdin.readline().split()))
d_a = list(map(int, stdin.readline().split()))
for i in range(n1):
	a_a[i] = [i, a_a[i]]
for i in range(n2):
	b_a[i] = [i, b_a[i]]
for i in range(n3):
	c_a[i] = [i, c_a[i]]
for i in range(n4):
	d_a[i] = [i, d_a[i]]
m1 = int(stdin.readline())
dic_a = {}
for _ in range(m1):
	(a, b) = map(int, stdin.readline().split())
	if a not in dic_a:
		dic_a[a] = set()
	dic_a[a].add(b)
m2 = int(stdin.readline())
dic_b = {}
for _ in range(m2):
	(b, c) = map(int, stdin.readline().split())
	if b not in dic_b:
		dic_b[b] = set()
	dic_b[b].add(c)
m3 = int(stdin.readline())
dic_c = {}
for _ in range(m3):
	(c, d) = map(int, stdin.readline().split())
	if c not in dic_c:
		dic_c[c] = set()
	dic_c[c].add(d)
r = cheap_dinner(n1, n2, n3, n4, a_a, b_a, c_a, d_a, dic_a, dic_b, dic_c)
stdout.write(str(r))


from sys import stdin
(n1, n2, n3, n4) = map(int, stdin.readline().split())
p1 = sorted(zip(map(int, stdin.readline().split()), range(1, n1 + 1)))
p2 = sorted(zip(map(int, stdin.readline().split()), range(1, n2 + 1)))
p3 = sorted(zip(map(int, stdin.readline().split()), range(1, n3 + 1)))
p4 = sorted(zip(map(int, stdin.readline().split()), range(1, n4 + 1)))
m1 = int(stdin.readline())
b1 = set()
for _ in range(m1):
	b1.add(tuple(map(int, stdin.readline().split())))
m2 = int(stdin.readline())
b2 = set()
for _ in range(m2):
	b2.add(tuple(map(int, stdin.readline().split())))
m3 = int(stdin.readline())
b3 = set()
for _ in range(m3):
	b3.add(tuple(map(int, stdin.readline().split())))

def f(pa, pb, b):
	output = []
	for j in range(len(pb)):
		(pricej, idxj) = pb[j]
		for i in range(len(pa)):
			(pricei, idxi) = pa[i]
			if (idxi, idxj) not in b:
				output.append((pricei + pricej, idxj))
				break
	return sorted(output)
o1 = f(p1, p2, b1)
o2 = f(o1, p3, b2)
o3 = f(o2, p4, b3)
if o3:
	print(min(o3)[0])
else:
	print(-1)


MAX_MIN_VAL = 10 ** 9

def getSortedIndices(A, n):
	P = []
	for i in range(n):
		P.append([A[i], i])
	P = sorted(P)
	return [i for (a, i) in P]

def getPositiveStartIndex(A, AIS, n):
	l = 0
	r = n - 1
	while l < r:
		m = (l + r) // 2
		if A[AIS[m]] < 0:
			l = m + 1
		else:
			r = m
	return l
(n1, n2, n3, n4) = map(int, input().split())
A = [MAX_MIN_VAL] + list(map(int, input().split()))
B = [MAX_MIN_VAL] + list(map(int, input().split()))
C = [MAX_MIN_VAL] + list(map(int, input().split()))
D = [MAX_MIN_VAL] + list(map(int, input().split()))
DS = getSortedIndices(D, n4 + 1)
m1 = int(input())
M1 = {}
for i in range(m1):
	(x, y) = map(int, input().split())
	M1[x] = M1.get(x, set())
	M1[x].add(y)
m2 = int(input())
M2 = {}
for i in range(m2):
	(x, y) = map(int, input().split())
	M2[x] = M2.get(x, set())
	M2[x].add(y)
m3 = int(input())
M3 = {}
for i in range(m3):
	(x, y) = map(int, input().split())
	M3[x] = M3.get(x, set())
	M3[x].add(y)
minResult = MAX_MIN_VAL
dp3 = [MAX_MIN_VAL]
for i in range(1, n3 + 1):
	dpVal = -1
	if i not in M3:
		dpVal = D[DS[0]]
	elif len(M3[i]) != n4:
		for j in DS:
			if j not in M3[i]:
				dpVal = D[j]
				break
	dp3.append(dpVal + C[i] if dpVal != -1 else -1)
dp3S = getSortedIndices(dp3, n3 + 1)
positiveStartIndex = getPositiveStartIndex(dp3, dp3S, n3 + 1)
min3 = -1 if positiveStartIndex == n3 else dp3[dp3S[positiveStartIndex]]
if min3 != -1:
	dp2 = [MAX_MIN_VAL]
	for i in range(1, n2 + 1):
		dpVal = -1
		if i not in M2:
			dpVal = min3
		elif len(M2[i]) != n3:
			for j in range(positiveStartIndex, n3):
				if dp3S[j] not in M2[i]:
					dpVal = dp3[dp3S[j]]
					break
		dp2.append(dpVal + B[i] if dpVal != -1 else -1)
	dp2S = getSortedIndices(dp2, n2 + 1)
	positiveStartIndex = getPositiveStartIndex(dp2, dp2S, n2 + 1)
	min2 = -1 if positiveStartIndex == n2 else dp2[dp2S[positiveStartIndex]]
	if min2 != -1:
		dp1 = [MAX_MIN_VAL]
		for i in range(1, n1 + 1):
			dpVal = -1
			if i not in M1:
				dpVal = min2
			elif len(M1[i]) != n2:
				for j in range(positiveStartIndex, n2):
					if dp2S[j] not in M1[i]:
						dpVal = dp2[dp2S[j]]
						break
			dp1.append(dpVal + A[i] if dpVal != -1 else -1)
		minResult = min([v for v in dp1 if v != -1])
result = minResult if minResult != MAX_MIN_VAL else -1
print(result)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def tree(si, ss, se, l, st):
	if ss == se:
		st[si] = l[ss]
		return st[si]
	mid = (ss + se) // 2
	st[si] = min(tree(2 * si, ss, mid, l, st), tree(2 * si + 1, mid + 1, se, l, st))
	return st[si]

def update(si, ss, se, ui, uv, l, st):
	if ss == se:
		st[si] = uv
		return st[si]
	mid = (ss + se) // 2
	if ui <= mid:
		update(2 * si, ss, mid, ui, uv, l, st)
	else:
		update(2 * si + 1, mid + 1, se, ui, uv, l, st)
	st[si] = min(st[2 * si], st[2 * si + 1])
	return st[si]
(n1, n2, n3, n4) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
m1 = int(input())
lm1 = [[] for i in range(n1)]
for i in range(m1):
	x = list(map(int, input().split()))
	lm1[x[0] - 1].append(x[1] - 1)
m2 = int(input())
lm2 = [[] for i in range(n2)]
for i in range(m2):
	x = list(map(int, input().split()))
	lm2[x[0] - 1].append(x[1] - 1)
m3 = int(input())
lm3 = [[] for i in range(n3)]
for i in range(m3):
	x = list(map(int, input().split()))
	lm3[x[0] - 1].append(x[1] - 1)
st2 = [0] * (4 * n2 + 1)
st3 = [0] * (4 * n3 + 1)
st4 = [0] * (4 * n4 + 1)
tree(1, 0, n4 - 1, l4, st4)
for i in range(n3):
	x = update(1, 0, n4 - 1, 0, l4[0], l4, st4)
	for j in lm3[i]:
		x = update(1, 0, n4 - 1, j, 1000000000, l4, st4)
	l3[i] += x
	for j in lm3[i]:
		update(1, 0, n4 - 1, j, l4[j], l4, st4)
tree(1, 0, n3 - 1, l3, st3)
for i in range(n2):
	x = update(1, 0, n3 - 1, 0, l3[0], l3, st3)
	for j in lm2[i]:
		x = update(1, 0, n3 - 1, j, 1000000000, l3, st3)
	l2[i] += x
	for j in lm2[i]:
		update(1, 0, n3 - 1, j, l3[j], l3, st3)
tree(1, 0, n2 - 1, l2, st2)
for i in range(n1):
	x = update(1, 0, n2 - 1, 0, l2[0], l2, st2)
	for j in lm1[i]:
		x = update(1, 0, n2 - 1, j, 1000000000, l2, st2)
	l1[i] += x
	for j in lm1[i]:
		update(1, 0, n2 - 1, j, l2[j], l2, st2)
ans = min(l1)
if ans >= 10 ** 9:
	print(-1)
else:
	print(ans)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def calc(p, forb, p2):
	ans = [10 ** 9] * len(p2)
	free = set(range(len(p2)))
	for i in sorted(range(len(p)), key=lambda x: p[x]):
		to_remove = []
		for val in free:
			if val not in forb[i]:
				ans[val] = p[i] + p2[val]
				to_remove.append(val)
		for val in to_remove:
			free.remove(val)
	return ans

def solve():
	(n1, n2, n3, n4) = map(int, input().split())
	p1 = list(map(int, input().split()))
	p2 = list(map(int, input().split()))
	p3 = list(map(int, input().split()))
	p4 = list(map(int, input().split()))
	forb1 = [set() for _ in range(n1)]
	m1 = int(input())
	for _ in range(m1):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		forb1[x].add(y)
	forb2 = [set() for _ in range(n2)]
	m2 = int(input())
	for _ in range(m2):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		forb2[x].add(y)
	forb3 = [set() for _ in range(n3)]
	m3 = int(input())
	for _ in range(m3):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		forb3[x].add(y)
	best_vals = calc(p1, forb1, p2)
	best_vals = calc(best_vals, forb2, p3)
	best_vals = calc(best_vals, forb3, p4)
	m = min(best_vals)
	if m < 10 ** 9:
		print(m)
	else:
		print(-1)
t = 1
for _ in range(t):
	solve()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n1, n2, n3, n4) = map(int, input().split())
a = []
[a.append([v, i]) for (i, v) in enumerate(map(int, input().split()))]
b = []
[b.append([v, i]) for (i, v) in enumerate(map(int, input().split()))]
c = []
[c.append([v, i]) for (i, v) in enumerate(map(int, input().split()))]
d = []
[d.append([v, i]) for (i, v) in enumerate(map(int, input().split()))]
ck1 = dict()
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ck1[y - 1] = ck1.get(y - 1, set())
	ck1[y - 1].add(x - 1)
ck2 = dict()
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ck2[y - 1] = ck2.get(y - 1, set())
	ck2[y - 1].add(x - 1)
ck3 = dict()
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ck3[y - 1] = ck3.get(y - 1, set())
	ck3[y - 1].add(x - 1)
d.sort()
s = set()
[s.add(i) for i in range(len(c))]
for (v, i) in d:
	if s:
		t = set()
		for j in s:
			if i not in ck3 or j not in ck3[i]:
				t.add(j)
				c[j][0] += v
		[s.remove(j) for j in t]
	else:
		break
if s:
	for i in s:
		c[i][0] = 0
c.sort()
s = set()
[s.add(i) for i in range(len(b))]
for (v, i) in c:
	if not v:
		continue
	if s:
		t = set()
		for j in s:
			if i not in ck2 or j not in ck2[i]:
				t.add(j)
				b[j][0] += v
		[s.remove(j) for j in t]
	else:
		break
if s:
	for i in s:
		b[i][0] = 0
b.sort()
s = set()
[s.add(i) for i in range(len(a))]
for (v, i) in b:
	if not v:
		continue
	if s:
		t = set()
		for j in s:
			if i not in ck1 or j not in ck1[i]:
				t.add(j)
				a[j][0] += v
		[s.remove(j) for j in t]
	else:
		break
if s:
	for i in s:
		a[i][0] = 0
ans = 100000000000
for (v, i) in a:
	if v:
		ans = min(ans, v)
if ans == 100000000000:
	print(-1)
else:
	print(ans)


import sys
import math
import collections
import bisect
import itertools
import decimal
import heapq
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.buffer.readline())

def ns():
	return map(int, sys.stdin.buffer.readline().split())

def na():
	return list(map(int, sys.stdin.buffer.readline().split()))

def na1():
	return list(map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split()))

def flush():
	return sys.stdout.flush()

def nicf():
	return int(sys.stdin.readline())

def nscf():
	return map(int, sys.stdin.readline().split())

def nacf():
	return list(map(int, sys.stdin.readline().split()))

def na1cf():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def main():
	(n1, n2, n3, n4) = ns()
	a = na()
	b = na()
	c = na()
	d = na()
	m1 = ni()
	m1l = set()
	for _ in range(m1):
		(x, y) = ns()
		(x, y) = (x - 1, y - 1)
		m1l.add((x, y))
	m2 = ni()
	m2l = set()
	for _ in range(m2):
		(x, y) = ns()
		(x, y) = (x - 1, y - 1)
		m2l.add((x, y))
	m3 = ni()
	m3l = set()
	for _ in range(m3):
		(x, y) = ns()
		(x, y) = (x - 1, y - 1)
		m3l.add((x, y))
	dp1 = [[a[i], i] for i in range(n1)]
	dp2 = [[INF, i] for i in range(n2)]
	dp3 = [[INF, i] for i in range(n3)]
	dp4 = [[INF, i] for i in range(n4)]

	def dp(dp, ndp, nv, rej):
		dp.sort()
		rem = [i for i in range(len(ndp))]
		que = collections.deque(rem)
		for i in range(len(dp)):
			if dp[i][0] == INF:
				continue
			for _ in range(len(que)):
				ri = que.popleft()
				if (dp[i][1], ri) not in rej:
					ndp[ri][0] = dp[i][0] + nv[ri]
				else:
					que.append(ri)
		return ndp
	dp2 = dp(dp1, dp2, b, m1l)
	dp3 = dp(dp2, dp3, c, m2l)
	dp4 = dp(dp3, dp4, d, m3l)
	ans = INF
	for (v, i) in dp4:
		ans = min(ans, v)
	print(ans if ans != INF else -1)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def S():
	return input().strip()

def print_list(l):
	print(' '.join(map(str, l)))
(n1, n2, n3, n4) = RL()
read = [RLL() for _ in range(4)]
a = read[0]
a = [(a[i], i) for i in range(n1)]
a.sort()
for w in range(1, 4):
	ban = set()
	nex = []
	b = read[w]
	for _ in range(N()):
		ban.add(tuple(RL()))
	for i in range(len(b)):
		for (v, j) in a:
			if (j + 1, i + 1) not in ban:
				nex.append((b[i] + v, i))
				break
	a = nex
	a.sort()
if not a:
	print(-1)
else:
	print(a[0][0])


mod = 1000000007
eps = 10 ** (-9)
inf = 10 ** 15

def main():
	import sys
	input = sys.stdin.buffer.readline

	def F(L, R, bad):
		NL = len(L)
		NR = len(R)
		ret = [inf] * NR
		L_sorted = [(l, i) for (i, l) in enumerate(L)]
		L_sorted.sort(key=lambda x: x[0])
		for (i, r) in enumerate(R):
			for (l, k) in L_sorted:
				if k * (NR + 1) + i in bad:
					continue
				else:
					ret[i] = l + r
					break
		return ret
	(N1, N2, N3, N4) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	D = list(map(int, input().split()))
	M1 = int(input())
	if M1 == N1 * N2:
		print(-1)
		exit()
	bad1 = set()
	for _ in range(M1):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		bad1.add(x * (N2 + 1) + y)
	M2 = int(input())
	if M2 == N2 * N3:
		print(-1)
		exit()
	bad2 = set()
	for _ in range(M2):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		bad2.add(x * (N3 + 1) + y)
	M3 = int(input())
	if M3 == N3 * N4:
		print(-1)
		exit()
	bad3 = set()
	for _ in range(M3):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		bad3.add(y * (N3 + 1) + x)
	L = F(A, B, bad1)
	R = F(D, C, bad3)
	ans = min(F(L, R, bad2))
	if ans < inf:
		print(ans)
	else:
		print(-1)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd
(n1, n2, n3, n4) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
d1 = dd(int)
d2 = dd(int)
d3 = dd(int)
m1 = int(input())
for i in range(m1):
	(x, y) = map(int, input().split())
	d1[x - 1, y - 1] = 1
m2 = int(input())
for i in range(m2):
	(x, y) = map(int, input().split())
	d2[x - 1, y - 1] = 1
m3 = int(input())
for i in range(m3):
	(x, y) = map(int, input().split())
	d3[x - 1, y - 1] = 1
l5 = []
for i in range(n4):
	l5.append([l4[i], i])
l5.sort()
for i in range(n3):
	x = 10 ** 9
	for j in range(n4):
		if not d3[i, l5[j][1]]:
			x = l5[j][0]
			break
	l3[i] += x
l6 = []
l7 = []
for i in range(n3):
	l6.append([l3[i], i])
l6.sort()
for i in range(n2):
	x = 10 ** 9
	for j in range(n3):
		if not d2[i, l6[j][1]]:
			x = l6[j][0]
			break
	l2[i] += x
for i in range(n2):
	l7.append([l2[i], i])
l7.sort()
for i in range(n1):
	x = 10 ** 9
	for j in range(n2):
		if not d1[i, l7[j][1]]:
			x = l7[j][0]
			break
	l1[i] += x
ans = min(l1)
if ans >= 10 ** 9:
	print(-1)
else:
	print(ans)