n = int(input())

Card = [[] for _ in [0]*n]

Cost = {}

for i in range(n):

  Card[i] = list(map(int, input().split()))

  Cost[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    Cost[(j, a)] = min([Card[j][0] * Card[k][1] * Card[k+1][0] * Card[a][1] + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])

print(Cost[0, n-1])
n = int(input())

C = [[] for _ in [0]*n]

W = {}

for i in range(n):

  C[i] = list(map(int, input().split()))

  W[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    W[(j, a)] = min([C[j][0] * C[k][1] * C[k+1][0] * C[a][1] + W[(j, k)] + W[(k+1, a)] for k in range(j, j+i)])

print(W[0, n-1])
n = int(input())
Card = [[] for _ in [0] * n]
Cost = {}
for i in range(n):
    Card[i] = list(map(int, input().split()))
    Cost[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        Cost[(j, a)] = min(
            [
                Card[j][0] * Card[k][1] * Card[k + 1][0] * Card[a][1]
                + Cost[(j, k)]
                + Cost[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(Cost[0, n - 1])

n = int(input())
C = [[] for _ in [0] * n]
W = {}
for i in range(n):
    C[i] = list(map(int, input().split()))
    W[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        W[(j, a)] = min(
            [
                C[j][0] * C[k][1] * C[k + 1][0] * C[a][1] + W[(j, k)] + W[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(W[0, n - 1])

-Card = [[] for _ in [0] * n] -Cost = {} +C = [[] for _ in [0] * n] +W = {} -    Card[i] = list(map(int, input().split())) -    Cost[(i, i)] = 0 +    C[i] = list(map(int, input().split())) +    W[(i, i)] = 0 -        Cost[(j, a)] = min( +        W[(j, a)] = min( -                Card[j][0] * Card[k][1] * Card[k + 1][0] * Card[a][1] -                + Cost[(j, k)] -                + Cost[(k + 1, a)] +                C[j][0] * C[k][1] * C[k + 1][0] * C[a][1] + W[(j, k)] + W[(k + 1, a)] -print(Cost[0, n - 1]) +print(W[0, n - 1])