At the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a ball, which will be attended by pairs of boys and girls.

Each class must present two couples to the ball. In Vasya's class, $a$ boys and $b$ girls wish to participate. But not all boys and not all girls are ready to dance in pairs.

Formally, you know $k$ possible one-boy-one-girl pairs. You need to choose two of these pairs so that no person is in more than one pair.

For example, if $a=3$, $b=4$, $k=4$ and the couples $(1, 2)$, $(1, 3)$, $(2, 2)$, $(3, 4)$ are ready to dance together (in each pair, the boy's number comes first, then the girl's number), then the following combinations of two pairs are possible (not all possible options are listed below):

$(1, 3)$ and $(2, 2)$;

$(3, 4)$ and $(1, 3)$;

But the following combinations are not possible:

$(1, 3)$ and $(1, 2)$ — the first boy enters two pairs;

$(1, 2)$ and $(2, 2)$ — the second girl enters two pairs;

Find the number of ways to select two pairs that match the condition above. Two ways are considered different if they consist of different pairs.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains three integers $a$, $b$ and $k$ ($1 \le a, b, k \le 2 \cdot 10^5$) — the number of boys and girls in the class and the number of couples ready to dance together.

The second line of each test case contains $k$ integers $a_1, a_2, \ldots a_k$. ($1 \le a_i \le a$), where $a_i$ is the number of the boy in the pair with the number $i$.

The third line of each test case contains $k$ integers $b_1, b_2, \ldots b_k$. ($1 \le b_i \le b$), where $b_i$ is the number of the girl in the pair with the number $i$.

It is guaranteed that the sums of $a$, $b$, and $k$ over all test cases do not exceed $2 \cdot 10^5$.

It is guaranteed that each pair is specified at most once in one test case.


-----Output-----

For each test case, on a separate line print one integer — the number of ways to choose two pairs that match the condition above.


-----Examples-----

Input
3
3 4 4
1 1 2 3
2 3 2 4
1 1 1
1
1
2 2 4
1 1 2 2
1 2 1 2
Output
4
0
2


-----Note-----

In the first test case, the following combinations of pairs fit:

$(1, 2)$ and $(3, 4)$;

$(1, 3)$ and $(2, 2)$;

$(1, 3)$ and $(3, 4)$;

$(2, 2)$ and $(3, 4)$.

There is only one pair in the second test case.

In the third test case, the following combinations of pairs fit:

$(1, 1)$ and $(2, 2)$;

$(1, 2)$ and $(2, 1)$.

Difficulty: MEDIUM

Solutions:
def solve():
	(n, m, no_pairs) = input().split()
	n = int(n)
	m = int(m)
	no_pairs = int(no_pairs)
	male = input().split()
	female = input().split()
	male_pair = [0] * n
	female_pair = [0] * m
	res = 0
	for i in male:
		male_pair[int(i) - 1] += 1
	for j in female:
		female_pair[int(j) - 1] += 1
	for i in range(len(male)):
		index_male = int(male[i])
		index_fmale = int(female[i])
		res += len(male) - male_pair[index_male - 1] - female_pair[index_fmale - 1] + 1
	return int(res / 2)
no_tests = int(input())
results = []
for i in range(no_tests):
	results.append(solve())
for result in results:
	print(result)


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
t = 1
t = int(input())
while t:
	t -= 1
	(a, b, k) = map(int, input().split())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	(nota, notb) = ({}, {})
	for i in range(k):
		if a1[i] in nota:
			nota[a1[i]].add(i)
		else:
			nota[a1[i]] = set([i])
		if b1[i] in notb:
			notb[b1[i]].add(i)
		else:
			notb[b1[i]] = set([i])
	ans = 0
	for i in range(k):
		ans += k - len(nota[a1[i]]) - len(notb[b1[i]]) + 1
	print(ans // 2)


from collections import defaultdict

def ball(a, b, k, boys, girls):
	boy = defaultdict(lambda : 0)
	girl = defaultdict(lambda : 0)
	for i in range(k):
		boy[boys[i]] += 1
		girl[girls[i]] += 1
	temp = 0
	for z in boy.keys():
		if boy[z] >= 2:
			temp += boy[z] * (boy[z] - 1) // 2
	for z in girl.keys():
		if girl[z] >= 2:
			temp += girl[z] * (girl[z] - 1) // 2
	total = k * (k - 1) // 2
	return total - temp
t = int(input())
for x in range(t):
	(a, b, k) = input().split()
	a = int(a)
	k = int(k)
	b = int(b)
	boys = [int(i) for i in input().split()][:k]
	girls = [int(i) for i in input().split()][:k]
	print(ball(a, b, k, boys, girls))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(5 * 10 ** 5)
inf = 10 ** 20
mod = 10 ** 9 + 7

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

def II():
	return int(input())

def LS():
	return list(input().split())

def S():
	return input()

def solve():
	ans = 0
	(a, b, k) = LI()
	x_list = LI()
	y_list = LI()
	a_num = [0 for _ in range(a)]
	b_num = [0 for _ in range(b)]
	for x in x_list:
		x -= 1
		a_num[x] += 1
	for y in y_list:
		y -= 1
		b_num[y] += 1
	for i in range(k):
		x = x_list[i] - 1
		y = y_list[i] - 1
		ans += k + 1 - a_num[x] - b_num[y]
	ans //= 2
	return ans

def main():
	t = II()
	res = list()
	for _ in range(t):
		res.append(solve())
	for ans in res:
		print(ans)
	return 0
main()


for T in range(int(input())):
	(a, b, k) = map(int, input().split())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	p = [0] * (a + 1)
	q = [0] * (b + 1)
	for i in l:
		p[i] += 1
	for i in m:
		q[i] += 1
	s = 0
	for i in range(k):
		s += k - p[l[i]] - q[m[i]] + 1
	print(s // 2)


import collections, sys, functools, heapq
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	boy = collections.Counter()
	girl = collections.Counter()
	for (i, j) in zip(a, b):
		boy[i] += 1
		girl[j] += 1
	ans = 0
	for (i, j) in zip(a, b):
		ans += k - (boy[i] - 1) - (girl[j] - 1) - 1
	print(ans // 2)


import sys
import math

def input():
	return sys.stdin.readline().strip('\n')

def I():
	return input()

def II():
	return int(input())

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

def LI():
	return list(map(int, input().split()))
for _ in range(II()):
	(a, b, k) = MI()
	aa = LI()
	bb = LI()
	d = [0] * a
	f = [0] * b
	for i in aa:
		d[i - 1] += 1
	for j in bb:
		f[j - 1] += 1
	ans = 0
	for i in range(a):
		ans += d[i] * (d[i] - 1) // 2
	for i in range(b):
		ans += f[i] * (f[i] - 1) // 2
	print(k * (k - 1) // 2 - ans)


T = int(input())
ans_ls = [0] * T

def db(*arg):
	print(*arg)
for t in range(T):
	(A, B, K) = map(int, input().split())
	a_ls = list(map(int, input().split()))
	b_ls = list(map(int, input().split()))
	a_count = [0] * A
	b_count = [0] * B
	for i in range(K):
		(a, b) = (a_ls[i], b_ls[i])
		a_count[a - 1] += 1
		b_count[b - 1] += 1
	ans = 0
	for i in range(K):
		(a, b) = (a_ls[i], b_ls[i])
		ans += max(0, K - (a_count[a - 1] + b_count[b - 1] - 1))
	ans_ls[t] = ans // 2
for ans in ans_ls:
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	da = defaultdict(int)
	db = defaultdict(int)
	for i in range(k):
		da[A[i]] += 1
		db[B[i]] += 1
	ans = 0
	for i in range(k):
		ans += k - 1 - (da[A[i]] - 1 + db[B[i]] - 1)
	print(ans // 2)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	(a, b, k) = inlt()
	ai = inlt()
	bi = inlt()
	ans = 0
	numa = [0] * a
	numb = [0] * b
	for j in ai:
		numa[j - 1] += 1
	for j in bi:
		numb[j - 1] += 1
	for index_pair in range(k):
		wasted = numa[ai[index_pair] - 1] + numb[bi[index_pair] - 1] - 1
		ans += k - wasted
	print(ans // 2)


import sys

def main():
	test_cases = int(sys.stdin.readline())
	for _ in range(test_cases):
		(boy_count, girl_count, pair_count) = (int(i) for i in sys.stdin.readline().split())
		boys = [int(i) for i in sys.stdin.readline().split()]
		girls = [int(i) for i in sys.stdin.readline().split()]
		boys_partners = [0 for _ in range(boy_count + 1)]
		girls_partners = [0 for _ in range(girl_count + 1)]
		for (b, g) in zip(boys, girls):
			boys_partners[b] += 1
			girls_partners[g] += 1
		soln = 0
		for (b, g) in zip(boys, girls):
			soln += pair_count - girls_partners[g] - boys_partners[b] + 1
		print(soln // 2)
main()


from collections import defaultdict
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:k]
	arr2 = list(map(int, input().strip().split()))[:k]
	boy = defaultdict(int)
	girl = defaultdict(int)
	for (i, j) in zip(arr, arr2):
		boy[i] += 1
		girl[j] += 1
	cnt = 0
	for i in range(k):
		cnt += k - boy[arr[i]] - girl[arr2[i]] + 1
	print(cnt // 2)


t = int(input())
for _ in range(t):
	(a, b, k) = [int(x) for x in input().split()]
	boy = [int(x) for x in input().split()]
	girl = [int(x) for x in input().split()]
	boy_dict = {}
	girl_dict = {}
	for i in boy:
		boy_dict[i] = boy_dict.get(i, 0) + 1
	for i in girl:
		girl_dict[i] = girl_dict.get(i, 0) + 1
	ans = k * (k - 1) // 2
	for (key, value) in boy_dict.items():
		ans -= value * (value - 1) // 2
	for (key, value) in girl_dict.items():
		ans -= value * (value - 1) // 2
	print(ans)


from collections import defaultdict as dd
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	bdict = dd(int)
	gdict = dd(int)
	for i in range(k):
		bdict[boys[i]] += 1
		gdict[girls[i]] += 1
	ans = 0
	for i in range(k):
		ans += k - 1 - bdict[boys[i]] - gdict[girls[i]] + 2
	print(ans // 2)


def main(b, g, k, X, Y):
	B = [0 for i in range(b + 1)]
	G = [0 for i in range(g + 1)]
	for i in range(k):
		B[X[i]] += 1
	for i in range(k):
		G[Y[i]] += 1
	res = 0
	for i in range(k):
		res += k - 1 - (B[X[i]] - 1) - (G[Y[i]] - 1)
	return int(res / 2)
m = int(input())
for _ in range(m):
	(b, g, k) = map(int, input().split())
	X = list(map(int, input().strip().split()))
	Y = list(map(int, input().strip().split()))
	print(main(b, g, k, X, Y))


import math, sys
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
INF = float('inf')
MOD = int(1000000000.0) + 7
MAX = int(1000000.0) + 1

def solve():
	(a, b, k) = vars()
	boys = array()
	girls = array()
	pair = []
	for i in range(k):
		pair.append([boys[i], girls[i]])
	pair = sorted(pair)
	index = defaultdict(list)
	for i in range(k):
		index[pair[i][1]].append(i)
	ans = 0
	i = 0
	while i < k:
		d = 0
		tmp = i
		while i < k - 1 and pair[i + 1][0] == pair[i][0]:
			i += 1
			d += 1
		db = i
		i = tmp
		while i <= db:
			girl = pair[i][1]
			discard = len(index[girl]) - bisect_right(index[girl], db)
			ans += k - db - discard - 1
			i += 1
	print(ans)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def input():
	return sys.stdin.readline().rstrip('\n').strip()

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)
primes = [1 for i in range(MAX)]

def sieve():
	global primes
	primes[0] = primes[1] = 0
	i = 2
	while i <= MAX ** 0.5:
		j = i * i
		while primes[i] and j < MAX:
			if j % i == 0:
				primes[j] = 0
			j += i
		i += 1

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

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


import sys

def comb(num):
	if num == 1:
		return 0
	else:
		return num * (num - 1) // 2
for i in range(int(sys.stdin.readline())):
	(a, b, k) = map(int, sys.stdin.readline().split())
	dica = {}
	dicb = {}
	for j in map(int, sys.stdin.readline().split()):
		if j not in dica:
			dica[j] = 1
		else:
			dica[j] += 1
	for j in map(int, sys.stdin.readline().split()):
		if j not in dicb:
			dicb[j] = 1
		else:
			dicb[j] += 1
	s = 0
	for j in dica:
		s += comb(dica[j])
	for j in dicb:
		s += comb(dicb[j])
	print(comb(k) - s)


for _ in range(int(input())):
	(B, G, K) = [int(x) for x in input().split()]
	Boys = [int(x) for x in input().split()]
	Girl = [int(x) for x in input().split()]
	BC = [0] * B
	GC = [0] * G
	for i in Boys:
		BC[i - 1] += 1
	for i in Girl:
		GC[i - 1] += 1
	cnt = lambda n: n * (n - 1) // 2
	answer = cnt(K)
	for i in BC:
		answer -= cnt(i)
	for i in GC:
		answer -= cnt(i)
	print(answer)


from collections import *
R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(*_, k) = R()
	print(k * k + k - sum((x * x for c in (R(), R()) for x in Counter(c).values())) >> 1)


from collections import Counter

def ballInBerland():
	for i in range(int(input())):
		(a, b, k) = list(map(int, input().split()))
		boys = list(map(int, input().split()))
		girls = list(map(int, input().split()))
		countBoys = Counter(boys)
		countGirls = Counter(girls)
		ans = 0
		for i in range(k):
			ans += k - countBoys[boys[i]] - countGirls[girls[i]] + 1
		print(ans // 2)
ballInBerland()


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
(tc,) = inp()
for _ in range(tc):
	(n, m, k) = inp()
	a = inp()
	b = inp()
	dega = [0] * (n + 1)
	degb = [0] * (m + 1)
	for (i, j) in zip(a, b):
		dega[i] += 1
		degb[j] += 1
	ans = 0
	for (i, j) in zip(a, b):
		ans += k - dega[i] - degb[j] + 1
	print(ans // 2)


def solve():
	(a, b, k) = map(int, input().split())
	res = 0
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	degA = [0] * a
	degB = [0] * b
	for i in range(k):
		degA[l1[i] - 1] += 1
		degB[l2[i] - 1] += 1
	poss = 0
	for i in range(k):
		deg1 = degA[l1[i] - 1]
		deg2 = degB[l2[i] - 1]
		poss += k - deg1 - deg2 + 1
	print(poss // 2)
	return
t = int(input())
for _ in range(t):
	solve()


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.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(io.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()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007

def si():
	return input()

def ii():
	return int(input())

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

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

def sout(v):
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1
t = ii()
while t:
	t -= 1
	(n, m, k) = mi()
	d1 = {}
	d2 = {}
	for i in range(1, n + 1):
		d1[i] = []
	for i in range(1, m + 1):
		d2[i] = []
	a = li()
	b = li()
	for i in range(k):
		d1[a[i]].append(b[i])
		d2[b[i]].append(a[i])
	c = 0
	a1 = [i for i in range(1, n + 1) if len(d1[i]) > 0]
	for i in a1:
		for j in d1[i]:
			c += k - len(d2[j]) - (len(d1[i]) - 1)
	print(c // 2)


import collections
t = int(input())
while t > 0:
	t -= 1
	(a, b, k) = [int(i) for i in input().split()]
	ans = 0
	degA = collections.Counter()
	degB = collections.Counter()
	a = []
	b = []
	for i in input().split():
		degA[i] += 1
		a.append(i)
	for i in input().split():
		degB[i] += 1
		b.append(i)
	for i in range(k):
		ans += k - degA[a[i]] - degB[b[i]] + 1
	print(ans // 2)


from abc import abstractproperty
t = int(input())
for _ in range(t):
	(A, B, k) = map(int, input().split())
	a = [0] * A
	b = [0] * B
	edges = []
	for (x, y) in zip(map(int, input().split()), map(int, input().split())):
		edges.append((x, y))
		a[x - 1] += 1
		b[y - 1] += 1
	ans = 0
	for (x, y) in edges:
		ans += k - a[x - 1] - b[y - 1] + 1
	print(ans // 2)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

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

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

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

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(a, b, k) = sp()
	arr = l()
	brr = l()
	pairs = set()
	(c1, c2) = (C(), C())
	answer = 0
	for i in range(k):
		answer += i - c1[arr[i]] - c2[brr[i]]
		c1[arr[i]] += 1
		c2[brr[i]] += 1
	out(answer)


def main():
	t = int(input())
	while t > 0:
		t -= 1
		(a, b, k) = map(int, input().split())
		boys = list(map(int, input().split()))
		girls = list(map(int, input().split()))
		Di = {}
		for i in boys:
			Di[i] = Di.get(i, 0) + 1
		gDi = {}
		for g in girls:
			gDi[g] = gDi.get(g, 0) + 1
		pairs = [(boys[i], girls[i]) for i in range(k)]
		count = 0
		for i in pairs:
			x = k - (Di[i[0]] + gDi[i[1]] - 1)
			count += x
		print(count // 2)
main()


def solve():
	(A, B, K) = map(int, input().split())
	par = list(map(int, input().split()))
	per = list(map(int, input().split()))
	edges = []
	a = [0] * (A + 1)
	b = [0] * (B + 1)
	for i in range(K):
		edges.append((par[i], per[i]))
	for (x, y) in edges:
		a[x] += 1
		b[y] += 1
	ans = 0
	for (x, y) in edges:
		ans += K - a[x] - b[y] + 1
	print(ans // 2)
for _ in range(int(input())):
	solve()


import sys
from collections import *
import math
import bisect

def input():
	return sys.stdin.readline()
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	boy = list(map(int, input().split()))
	girl = list(map(int, input().split()))
	bb = Counter(boy)
	gg = Counter(girl)
	pair = k * (k - 1) // 2
	for i in range(k):
		num = boy[i]
		num2 = girl[i]
		bb[num] -= 1
		gg[num2] -= 1
		pair -= bb[num] + gg[num2]
	print(pair)


t = int(input())
for i in range(t):
	(a, b, k) = map(int, input().split())
	boy = list(map(int, input().split()))
	girl = list(map(int, input().split()))
	col = [0] * (b + 1)
	row = [0] * (a + 1)
	for j in range(k):
		col[girl[j]] += 1
		row[boy[j]] += 1
	sum = 0
	for m in range(k):
		sum += k - row[boy[m]] - col[girl[m]] + 1
	print(sum // 2)


from collections import Counter
t = int(input())
for z in range(t):
	(a, b, k) = [int(q) for q in input().split()]
	al = [int(q) for q in input().split()]
	bl = [int(q) for q in input().split()]
	alc = Counter(al)
	blc = Counter(bl)
	ans = 0
	for i in range(k):
		da = alc[al[i]]
		db = blc[bl[i]]
		ans += k - da - db + 1
	print(ans // 2)


from collections import defaultdict

def count_pairs(pairs):
	pairs_length = len(pairs)
	man_pairs = defaultdict(lambda : 0)
	woman_pairs = defaultdict(lambda : 0)
	count = 0
	for (man, woman) in pairs:
		man_pairs[man] += 1
		woman_pairs[woman] += 1
	for (man, woman) in pairs:
		suitable_pairs = pairs_length - man_pairs[man] - woman_pairs[woman] + 1
		count += suitable_pairs
	return count // 2
results = []
for _ in range(int(input())):
	(man_n, woman_n, _) = [int(s) for s in input().split(' ')]
	man = [int(s) for s in input().split(' ')]
	woman = [int(s) for s in input().split(' ')]
	pairs = list(zip(man, woman))
	results.append(str(count_pairs(pairs)))
print('\n'.join(results))


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
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
mod = pow(10, 9) + 7
mod2 = 998244353

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

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 isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(a, b, k) = mp()
	boys = lmp()
	girls = lmp()
	md = {}
	for i in range(a):
		md[i + 1] = 0
	for i in boys:
		md[i] += 1
	mdg = {}
	for i in range(b):
		mdg[i + 1] = 0
	for i in girls:
		mdg[i] += 1
	ml = [(girls[i], boys[i]) for i in range(k)]
	ans = 0
	for i in ml:
		(ng, nb) = i
		ans += k - md[nb] - (mdg[ng] - 1)
	print(ans // 2)


t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	ans = k * (k - 1) // 2
	dic1 = {}
	dic2 = {}
	for i in range(k):
		if a1[i] in dic1:
			dic1[a1[i]] += 1
		else:
			dic1[a1[i]] = 1
		if b1[i] in dic2:
			dic2[b1[i]] += 1
		else:
			dic2[b1[i]] = 1
	for i in dic1:
		r = dic1[i]
		ans -= r * (r - 1) // 2
	for i in dic2:
		r = dic2[i]
		ans -= r * (r - 1) // 2
	print(ans)


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math

def geti():
	return map(int, input().strip().split())

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

def getis():
	return map(str, input().strip().split())

def getls():
	return list(map(str, input().strip().split()))

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

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	for _ in range(geta()):
		(a, b, k) = geti()
		count_a = dd(int)
		count_b = dd(int)
		count_pair = dd(int)
		b = getl()
		g = getl()
		for i in range(k):
			count_a[b[i]] += 1
			count_b[g[i]] += 1
			count_pair[b[i], g[i]] += 1
		ans = 0
		for i in range(k):
			total = k - (count_a[b[i]] - 1) - (count_b[g[i]] - 1) + (count_pair[b[i], g[i]] - 1) - i
			ans += max(total - 1, 0)
			count_a[b[i]] -= 1
			count_b[g[i]] -= 1
			count_pair[b[i], g[i]] -= 1
		print(ans)
solve()


import sys
import array

def solve(a: int, b: int, k: int, boy_indices: list, girl_indices: list) -> int:
	ans = 0
	boy_connections = array.array('i', [0 for i in range(a)])
	girl_connections = array.array('i', [0 for i in range(b)])
	for i in range(k):
		boy_connections[boy_indices[i] - 1] += 1
		girl_connections[girl_indices[i] - 1] += 1
	for i in range(k):
		boy_index = boy_indices[i] - 1
		girl_index = girl_indices[i] - 1
		ans += -boy_connections[boy_index] - girl_connections[girl_index] + 1 + k
	ans = int(ans / 2)
	return ans
t = int(sys.stdin.readline())
for i in range(t):
	line = sys.stdin.readline()
	data = line.split(' ')
	a = int(data[0])
	b = int(data[1])
	k = int(data[2])
	boys = [int(x) for x in sys.stdin.readline().split()]
	girls = [int(x) for x in sys.stdin.readline().split()]
	print(solve(a, b, k, boys, girls))


t = int(input())
for i in range(t):
	ans = 0
	(a, b, k) = map(int, input().split())
	dictA = {}
	dictB = {}
	for j in range(1, a + 1):
		dictA[j] = 0
	for j in range(1, b + 1):
		dictB[j] = 0
	boy = [int(x) for x in input().split()]
	girl = [int(x) for x in input().split()]
	for x in boy:
		dictA[int(x)] += 1
	for x in girl:
		dictB[int(x)] += 1
	for j in range(k):
		ans += k - dictA[boy[j]] - dictB[girl[j]] + 1
	print(ans // 2)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	boy = {}
	girl = {}
	for i in range(k):
		boy[a[i]] = boy.get(a[i], 0) + 1
		girl[b[i]] = girl.get(b[i], 0) + 1
	res = 0
	for i in range(k):
		res += k - 1 - (boy[a[i]] - 1) - (girl[b[i]] - 1)
	print(res // 2)


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	k = int(l[2])
	a = input().split()
	ai = [int(i) for i in a]
	b = input().split()
	bi = [int(i) for i in b]
	hashi = dict()
	lol = dict()
	for i in range(k):
		if ai[i] not in hashi:
			hashi[ai[i]] = 0
		hashi[ai[i]] += 1
	for i in range(k):
		if bi[i] not in lol:
			lol[bi[i]] = 0
		lol[bi[i]] += 1
	sumi = 0
	ok = 0
	for i in hashi:
		sumi += hashi[i]
		ok += hashi[i] ** 2
	z = (sumi ** 2 - ok) // 2
	for i in lol:
		y = lol[i]
		z -= y * (y - 1) // 2
	print(z)


for i in range(int(input().strip())):
	(a, b, k) = map(int, input().strip().split())
	boy = list(map(int, input().strip().split()))
	girl = list(map(int, input().strip().split()))
	pairs = []
	cntg = [0] * (b + 1)
	cntb = [0] * (a + 1)
	for i in range(k):
		cntg[girl[i]] += 1
		cntb[boy[i]] += 1
	ans = 0
	for i in range(k):
		ans += k - (cntb[boy[i]] + cntg[girl[i]]) + 1
	ans = ans // 2
	print(ans)


def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
t = int(input())
for _ in range(t):
	(a, b, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(d, p) = ({}, {})
	for i in A:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for i in B:
		if i in p:
			p[i] += 1
		else:
			p[i] = 1
	total = 0
	for i in range(k):
		total += k - 1 - (d[A[i]] - 1) - (p[B[i]] - 1)
	print(int(total / 2))


import sys
import math
from collections import defaultdict, Counter
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')
t = int(input())
for i in range(t):
	(a, b, k) = map(int, input().split())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	ac = Counter(a1)
	bc = Counter(b1)
	ans = 0
	for (a, b) in zip(a1, b1):
		k -= 1
		ac[a] -= 1
		bc[b] -= 1
		ans += k - ac[a] - bc[b]
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	(a, b, k) = map(int, input().split())
	all = k * (k - 1) // 2
	aa = [0] * (a + 1)
	bb = [0] * (b + 1)
	for i in map(int, input().split()):
		aa[i] += 1
	for i in map(int, input().split()):
		bb[i] += 1
	for i in range(1, a + 1):
		all -= aa[i] * (aa[i] - 1) // 2
	for i in range(1, b + 1):
		all -= bb[i] * (bb[i] - 1) // 2
	print(all)
for i in range(int(input())):
	solve()


tc = int(input())
for _ in range(tc):
	(a, b, k) = list(map(int, input().split()))
	ak = list(map(int, input().split()))
	bk = list(map(int, input().split()))
	p = []
	for i in zip(ak, bk):
		p.append(i)
	x = {}
	y = {}
	for i in p:
		if i[0] in x:
			x[i[0]] += 1
		else:
			x[i[0]] = 1
		if i[1] in y:
			y[i[1]] += 1
		else:
			y[i[1]] = 1
	s = 0
	for i in p:
		s += k - (x[i[0]] + y[i[1]] - 1)
	print(s // 2)


t = int(input())
while t > 0:
	(a, b, k) = map(int, input().split())
	boy = list(map(int, input().split()))
	girl = list(map(int, input().split()))
	c_boy = [0] * (a + 1)
	c_girl = [0] * (b + 1)
	for i in range(k):
		c_boy[boy[i]] += 1
		c_girl[girl[i]] += 1
	ans = 0
	for i in range(k):
		ans = ans - c_boy[boy[i]] - c_girl[girl[i]] + k + 1
	print(int(ans / 2))
	t -= 1


def distinct_pairs(boys, girls, k):
	hash_map_boys = {}
	hash_map_girls = {}
	for i in range(k):
		if boys[i] in hash_map_boys:
			hash_map_boys[boys[i]] += 1
		else:
			hash_map_boys[boys[i]] = 1
		if girls[i] in hash_map_girls:
			hash_map_girls[girls[i]] += 1
		else:
			hash_map_girls[girls[i]] = 1
	count = 0
	for i in range(k):
		count += k - (hash_map_boys[boys[i]] + hash_map_girls[girls[i]]) + 1
	return count // 2
T = int(input())
for _ in range(T):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	count = distinct_pairs(boys, girls, k)
	print(count)


from collections import Counter
t = int(input())
for _ in range(t):
	(x, y, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	remove = 0
	for i in Counter(a).values():
		remove += i * (i - 1) // 2
	for i in Counter(b).values():
		remove += i * (i - 1) // 2
	print(k * (k - 1) // 2 - remove)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
pl = lambda l: print(' '.join(list(map(str, l))))

def d(a):
	d = {}
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	return d
for _ in range(rn()):
	(a, b, k) = rns()
	A = rl()
	B = rl()
	boys = {}
	girls = {}
	for i in range(k):
		if A[i] not in boys:
			boys[A[i]] = []
		boys[A[i]].append(B[i])
		if B[i] not in girls:
			girls[B[i]] = 0
		girls[B[i]] += 1
	ans = 0
	for i in boys:
		for j in boys[i]:
			ans += k - len(boys[i]) - girls[j] + 1
	print(ans // 2)


def main():
	for _ in range(int(input())):
		(a, b, k) = map(int, input().split())
		(ca, cb, r) = ([0] * (a + 1), [0] * (b + 1), 0)
		for (i, a, b) in zip(range(k), map(int, input().split()), map(int, input().split())):
			r += i - ca[a] - cb[b]
			ca[a] += 1
			cb[b] += 1
		print(r)
main()


def cut(lst1, lst2):
	d1 = {}
	d2 = {}
	for i in lst1:
		try:
			d1[i] += 1
		except:
			d1[i] = 1
	for i in lst2:
		try:
			d2[i] += 1
		except:
			d2[i] = 1
	s = 0
	for i in range(len(lst1)):
		a = lst1[i]
		b = lst2[i]
		s += len(lst1) - d1[a] - d2[b] + 1
	print(s // 2)
t = int(input())
for i in range(t):
	input().split()
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	cut(l1, l2)


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	counta = [0 for _ in range(a)]
	countb = [0 for _ in range(b)]
	arra = list(map(int, input().split()))
	arrb = list(map(int, input().split()))
	for x in range(k):
		counta[arra[x] - 1] += 1
	for y in range(k):
		countb[arrb[y] - 1] += 1
	count = k * (k - 1)
	for x in counta:
		count -= x * (x - 1)
	for y in countb:
		count -= y * (y - 1)
	print(count // 2)


t = int(input())
from collections import defaultdict
for i in range(0, t):
	(a, b, k) = map(int, input().split())
	lis1 = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	dic1 = defaultdict(int)
	dic2 = defaultdict(int)
	ans = 0
	for j in range(0, k):
		dic1[lis1[j]] = dic1[lis1[j]] + 1
		dic2[lis2[j]] = dic2[lis2[j]] + 1
	ans = k * (k - 1) // 2
	for j in dic1:
		if dic1[j] > 1:
			ans = ans - dic1[j] * (dic1[j] - 1) // 2
	for j in dic2:
		if dic2[j] > 1:
			ans = ans - dic2[j] * (dic2[j] - 1) // 2
	print(ans)


import sys
input = sys.stdin.readline
from collections import Counter
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	b_input = list(map(int, input().split()))
	g_input = list(map(int, input().split()))
	pairs = zip(b_input, g_input)
	boys = Counter(b_input)
	girls = Counter(g_input)
	count = 0
	for (a, b) in pairs:
		count += k - boys[a] - girls[b] + 1
	print(count // 2)


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(an, bn, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ca = Counter(a)
	cb = Counter(b)
	ans = 0
	for i in range(k):
		ans += k - ca[a[i]] - cb[b[i]] + 1
	print(ans // 2)


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	L = [[la[i], lb[i]] for i in range(k)]
	L.sort()
	La = []
	Lb = []
	preva = 0
	prevb = 0
	for i in range(k):
		if (L[i][0] == preva and L[i][1] == prevb) == 0:
			La.append(la[i])
			Lb.append(lb[i])
	X = len(La)
	Y = len(Lb)
	preva = 0
	prevb = 0
	ca = 0
	cb = 0
	count = 0
	La.sort()
	for i in range(len(La)):
		if La[i] == preva:
			ca += 1
		else:
			count += ca * (ca + 1) // 2
			preva = La[i]
			ca = 0
	count += ca * (ca + 1) // 2
	Lb.sort()
	for i in range(len(Lb)):
		if Lb[i] == prevb:
			cb += 1
		else:
			count += cb * (cb + 1) // 2
			prevb = Lb[i]
			cb = 0
	count += cb * (cb + 1) // 2
	Count = len(La) * (len(La) - 1) // 2
	print(Count - count)


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	deg_a = [0] * (a + 1)
	deg_b = [0] * (b + 1)
	for i in range(k):
		deg_a[A[i]] += 1
		deg_b[B[i]] += 1
	ans = 0
	for i in range(k):
		ans += k - deg_a[A[i]] - deg_b[B[i]] + 1
	print(ans // 2)


T = int(input())
for case in range(T):
	(a, b, k) = map(int, input().split())
	boy = list(map(int, input().split()))
	girl = list(map(int, input().split()))
	cnt1 = {}
	cnt2 = {}
	for ele in boy:
		if ele not in cnt1:
			cnt1[ele] = 1
		else:
			cnt1[ele] += 1
	for ele in girl:
		if ele not in cnt2:
			cnt2[ele] = 1
		else:
			cnt2[ele] += 1
	ans = 0
	for i in range(k):
		ans += k - (cnt1[boy[i]] + cnt2[girl[i]]) + 1
	print(ans // 2)


t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	ad = {}
	bd = {}
	p = list(map(int, input().split()))
	q = list(map(int, input().split()))
	ans = k * (k - 1) // 2
	for el in p:
		if el in ad:
			ad[el] += 1
		else:
			ad[el] = 1
	for el in q:
		if el in bd:
			bd[el] += 1
		else:
			bd[el] = 1
	s1 = 0
	s2 = 0
	for k in ad:
		s1 += ad[k] * (ad[k] - 1) // 2
	for k in bd:
		s2 += bd[k] * (bd[k] - 1) // 2
	print(max(0, ans - s1 - s2))


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

class _dict:

	def __init__(self):
		self.dict = dict()

	def __getitem__(self, key):
		if key in self.dict:
			return self.dict[key]
		else:
			return 0

	def __setitem__(self, key, value):
		self.dict[key] = value
yes = 'YES\n'
no = 'NO\n'
(n,) = readint()
while n > 0:
	n -= 1
	(a, b, k) = readint()
	l1 = readint()
	l2 = readint()
	fr1 = _dict()
	fr2 = _dict()
	for (i, _) in enumerate(l1):
		x = l1[i]
		y = l2[i]
		fr1[x] += 1
		fr2[y] += 1
	res = 0
	for (i, _) in enumerate(l1):
		x = l1[i]
		y = l2[i]
		res += k
		res -= fr1[x]
		res -= fr2[y]
		res += 1
	print(res // 2)


list_ans = []
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	ans = 0
	dictb = {}
	dictg = {}
	listb = list(map(int, input().split()))
	listg = list(map(int, input().split()))
	for b in listb:
		dictb[b] = dictb.get(b, 0) + 1
	for g in listg:
		dictg[g] = dictg.get(g, 0) + 1
	for i in range(k):
		b = listb[i]
		g = listg[i]
		ans += k - dictb[b] - dictg[g] + 1
	list_ans.append(ans // 2)
print(*list_ans, sep='\n')


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	bl = list(map(int, input().split()))
	gl = list(map(int, input().split()))
	aa = [0] * a
	bb = [0] * b
	for i in bl:
		aa[i - 1] += 1
	for i in gl:
		bb[i - 1] += 1
	s = k * (k - 1)
	for i in aa + bb:
		s -= i * (i - 1)
	print(s // 2)


def solve():
	(a, b, k) = [int(s) for s in input().split()]
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	a = sorted(a)
	b = sorted(b)
	total = k * (k - 1) // 2
	in_a_row = 0
	in_b_row = 0
	for i in range(k - 1):
		if a[i] == a[i + 1]:
			in_a_row += 1
			total -= in_a_row
		else:
			in_a_row = 0
		if b[i] == b[i + 1]:
			in_b_row += 1
			total -= in_b_row
		else:
			in_b_row = 0
	print(total)
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	b_dict = {}
	g_dict = {}
	for boy in boys:
		if boy in b_dict:
			b_dict[boy] += 1
		else:
			b_dict[boy] = 1
	for girl in girls:
		if girl in g_dict:
			g_dict[girl] += 1
		else:
			g_dict[girl] = 1
	tot = 0
	for i in range(k):
		tot += k - b_dict[boys[i]] - g_dict[girls[i]] + 1
	print(tot // 2)


for _ in range(int(input())):
	(a, b, k) = input().split()
	(a, b, k) = (int(a), int(b), int(k))
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	boy = {}
	girl = {}
	ans = 0
	for i in a1:
		if i in boy:
			boy[i] += 1
		else:
			boy[i] = 1
	for i in b1:
		if i in girl:
			girl[i] += 1
		else:
			girl[i] = 1
	for i in range(k):
		ans += k - 1 - (boy[a1[i]] - 1) - (girl[b1[i]] - 1)
	print(ans // 2)


from math import comb

def ball(am, bm, a, b, k):
	cnta = [0] * (am + 1)
	cntb = [0] * (bm + 1)
	for i in a:
		cnta[i] += 1
	for i in b:
		cntb[i] += 1
	(difa, difb) = (0, 0)
	for i in cnta:
		if i > 1:
			difa += comb(i, 2)
	for i in cntb:
		if i > 1:
			difb += comb(i, 2)
	return comb(k, 2) - difa - difb
for i in range(int(input())):
	(a, b, c) = map(int, input().strip().split())
	lst1 = list(map(int, input().strip().split()))
	lst2 = list(map(int, input().strip().split()))
	print(ball(a, b, lst1, lst2, c))


from typing import List
from collections import defaultdict

def count_pairs(boys: List[int], girls: List[int], candidates: int) -> int:
	(degrees, counter) = (defaultdict(int), 0)
	for (node_a, node_b) in zip(boys, girls):
		degrees[node_a + 'B'] += 1
		degrees[node_b + 'G'] += 1
	for (node_a, node_b) in zip(boys, girls):
		counter += candidates - (degrees[node_a + 'B'] + degrees[node_b + 'G'] - 1)
	return counter // 2

def read_input(filename: str=None) -> None:
	from sys import stdin
	stdin = open(filename) if filename else stdin
	cases = int(stdin.readline())
	while cases:
		cases = cases - 1
		(_, _, candidates) = tuple(map(int, stdin.readline().split()))
		boys = stdin.readline().split()
		girls = stdin.readline().split()
		print(count_pairs(boys, girls, candidates))

def main():
	read_input()
main()


from math import comb
from collections import Counter

def pairs(size, arr1, arr2):
	cmb = comb(size, 2)
	(dct1, dct2) = (Counter(arr1), Counter(arr2))
	for i in list(dct1):
		if dct1[i] > 1:
			cmb -= comb(dct1[i], 2)
	for j in list(dct2):
		if dct2[j] > 1:
			cmb -= comb(dct2[j], 2)
	return cmb
for test in range(int(input())):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	print(pairs(k, boys, girls))


testcases = int(input())
i = 0
dec = []
while i < testcases:
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	boy_in_couple = list(map(int, input().strip().split()))
	girl_in_couple = list(map(int, input().strip().split()))
	i += 1
	if a == 1 or b == 1 or c == 1:
		dec.append(0)
	else:
		B = {}
		G = {}
		for j in range(0, c):
			if boy_in_couple[j] in B:
				B[boy_in_couple[j]] += 1
			elif boy_in_couple[j] not in B:
				B[boy_in_couple[j]] = 1
			if girl_in_couple[j] in G:
				G[girl_in_couple[j]] += 1
			elif girl_in_couple[j] not in G:
				G[girl_in_couple[j]] = 1
		ways = c * (c - 1)
		for key in B.keys():
			ways -= B[key] * (B[key] - 1)
		for key in G.keys():
			ways -= G[key] * (G[key] - 1)
		dec.append(max(int(ways / 2), 0))
for i in range(0, testcases):
	print(dec[i])


import sys
input = sys.stdin.readline
g = int(input())
for i in range(g):
	(a, b, k) = list(map(int, input().split()))
	(n, m) = ([0] * (a + 1), [0] * (b + 1))
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	for i in range(k):
		n[list1[i]] += 1
	for i in range(k):
		m[list2[i]] += 1
	(i, res) = (0, 0)
	while i < k:
		res += k - 1 - (n[list1[i]] - 1) - (m[list2[i]] - 1)
		i += 1
	print(res // 2)


from collections import defaultdict
from collections import Counter
import math
import sys
import os
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 listt():
	return [int(i) for i in input().split()]

def gcd(a, b):
	return math.gcd(a, b)

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

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(math.sqrt(n)) + 1, step) if n % i == 0)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans

def is_prime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n > 2 and n % 2 == 0:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(3, 1 + max_div, 2):
		if n % i == 0:
			return False
	return True

def maxpower(n, x):
	B_max = int(math.log(n, x)) + 1
	return B_max

def binaryToDecimal(n):
	return int(n, 2)
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	l = listt()
	l1 = listt()
	db = defaultdict(int)
	dg = defaultdict(int)
	for (i, j) in zip(l, l1):
		db[i] += 1
		dg[j] += 1
	ans = 0
	for i in range(k):
		ans += k - (db[l[i]] + dg[l1[i]] - 1)
	print(ans // 2)


from collections import Counter
t = int(input())
result = []
for _ in range(t):
	(a, b, k) = (int(n) for n in input().split())
	boys = [int(n) for n in input().split()]
	girls = [int(n) for n in input().split()]
	all_pairs = zip(boys, girls)
	boys_cnt = Counter(boys)
	girls_cnt = Counter(girls)
	res = 0
	for (i, pair) in enumerate(all_pairs):
		the_boy = pair[0]
		the_girl = pair[1]
		res += k - 1 - (boys_cnt[the_boy] - 1) - (girls_cnt[the_girl] - 1)
	result.append(int(res / 2))
for n in result:
	print(n)


t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	c1 = [0] * a
	c2 = [0] * b
	for i in arr:
		c1[i - 1] += 1
	for i in brr:
		c2[i - 1] += 1
	ans = k * (k - 1) // 2
	for i in c1:
		ans -= i * (i - 1) // 2
	for i in c2:
		ans -= i * (i - 1) // 2
	print(ans)


R = lambda : list(map(int, input().split()))
for _ in ' ' * int(input()):
	(an, bn, k) = R()
	a = R()
	b = R()
	edges = []
	for i in range(k):
		edges.append([a[i], b[i]])
	dega = [0] * (an + 1)
	degb = [0] * (bn + 1)
	for (boy, girl) in edges:
		dega[boy] += 1
		degb[girl] += 1
	c = 0
	for (b, g) in edges:
		c += k + 1 - dega[b] - degb[g]
	print(c // 2)


for tests in range(int(input())):
	(a, b, k) = map(int, input().split())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	d = {}
	g = {}
	for i in range(k):
		if d.get(la[i]) == None:
			d[la[i]] = 1
		else:
			d[la[i]] += 1
		if g.get(lb[i]) == None:
			g[lb[i]] = 1
		else:
			g[lb[i]] += 1
	sum = 0
	for i in range(k):
		x = la[i]
		y = lb[i]
		sum += k - i - d[x] - g[y] + 1
		d[x] -= 1
		g[y] -= 1
	print(sum)


from collections import Counter
import operator as op
from functools import reduce

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def fun(A, B):
	if len(A) < 2:
		print(0)
		return
	p = Counter(A)
	q = Counter(B)
	Ans = ncr(len(A), 2)
	for i in p:
		if p[i] > 1:
			Ans -= ncr(p[i], 2)
	for i in q:
		if q[i] > 1:
			Ans -= ncr(q[i], 2)
	print(Ans)
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	fun(boys, girls)


def solv(pair, m_r, w_r, m, w):
	sa = [0] * (m + 1)
	sb = [0] * (w + 1)
	for i in range(pair):
		sa[m_r[i]] += 1
		sb[w_r[i]] += 1
	summ = 0
	for i in range(pair):
		summ += k - sa[m_r[i]] - sb[w_r[i]] + 1
	return summ // 2
for i in range(int(input())):
	(m, w, k) = map(int, input().split())
	m_r = list(map(int, input().split()))
	w_r = list(map(int, input().split()))
	print(solv(k, m_r, w_r, m, w))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(a, b, k) = inp()
	x = list(inp())
	y = list(inp())
	dica = Counter()
	dicb = Counter()
	ch = dd(int)
	ans = k * (k - 1) // 2
	for i in range(k):
		if i == 0:
			dica[x[i]] += 1
			dicb[y[i]] += 1
			ch[x[i], y[i]] += 1
		else:
			xx = x[i]
			yy = y[i]
			cal = dica[xx]
			cal += dicb[yy]
			cal -= ch[xx, yy]
			ans -= cal
			dica[xx] += 1
			dicb[yy] += 1
			ch[xx, yy] += 1
	print(ans)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

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

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

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))
for _ in range(inp()):
	(a, b, k) = inpl()
	A = inpl()
	B = inpl()
	aa = [0] * (a + 1)
	bb = [0] * (b + 1)
	for x in A:
		aa[x] += 1
	for x in B:
		bb[x] += 1
	res = 0
	for i in range(k):
		res += k - (aa[A[i]] + bb[B[i]] - 1)
	print(res // 2)


__version__ = '1.0'
__date__ = '2021-03-15'
import sys
from math import comb
from collections import Counter

def solve(a, b, k, aa, bb):
	answer = comb(k, 2)
	for c in Counter(aa).values():
		if c > 1:
			answer = answer - comb(c, 2)
	for c in Counter(bb).values():
		if c > 1:
			answer = answer - comb(c, 2)
	return answer

def main(argv=None):
	t = int(input())
	for _ in range(t):
		(a, b, k) = map(int, input().split())
		aa = list(map(int, input().split()))
		bb = list(map(int, input().split()))
		print(solve(a, b, k, aa, bb))
	return 0
STATUS = main()
sys.exit(STATUS)


from collections import Counter

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

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(a, b, k) = read_ints()
	pa = list(read_ints())
	pb = list(read_ints())
	ca = Counter()
	cb = Counter()
	for i in range(k):
		ca[pa[i]] += 1
		cb[pb[i]] += 1
	ans = 0
	for i in range(k - 1):
		ca[pa[i]] -= 1
		cb[pb[i]] -= 1
		ans += k - i - 1 - ca[pa[i]] - cb[pb[i]]
	print(ans)


t = int(input())
for l in range(0, t):
	(a, b, k) = map(int, input().split())
	zc1 = list(map(int, input().split()))
	zc2 = list(map(int, input().split()))
	ys1 = {}
	ys2 = {}
	for i in range(0, k):
		if ys1.get(zc1[i], -1) == -1:
			ys1[zc1[i]] = 1
		else:
			ys1[zc1[i]] += 1
		if ys2.get(zc2[i], -1) == -1:
			ys2[zc2[i]] = 1
		else:
			ys2[zc2[i]] += 1
	print('%d' % (sum((k - ys1[zc1[i]] - ys2[zc2[i]] + 1 for i in range(0, k))) / 2))


from collections import defaultdict
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	a = input().split()
	b = input().split()
	dic = defaultdict(lambda : -1)
	adic = defaultdict(lambda : -1)
	bdic = defaultdict(lambda : -1)
	for i in range(k):
		ai = int(a[i])
		bi = int(b[i])
		dic[ai, bi] += 1
		if dic[ai, bi] == 0:
			adic[ai] += 1
			bdic[bi] += 1
	ans = 0
	dl = len(dic)
	for i in range(k):
		ai = int(a[i])
		bi = int(b[i])
		if adic[ai] < 0 or bdic[bi] < 0 or dic[ai, bi] < 0:
			continue
		temp = dl - adic[ai] - bdic[bi] - 1
		dl -= 1
		dic[ai, bi] = 0
		adic[ai] -= 1
		bdic[bi] -= 1
		if temp > 0:
			ans += temp
	print(ans)


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

def read_one_int():
	return int(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def check_seq(k, a_lst, b_lst):
	res = 0
	a_to_b = {}
	b_to_a = {}
	for i in range(k):
		if a_lst[i] not in a_to_b:
			a_to_b[a_lst[i]] = []
		a_to_b[a_lst[i]].append(b_lst[i])
		if b_lst[i] not in b_to_a:
			b_to_a[b_lst[i]] = []
		b_to_a[b_lst[i]].append(a_lst[i])
	for (a_cur, a_mp) in a_to_b.items():
		for b_cur in a_mp:
			res += k - len(a_mp) - len(b_to_a[b_cur]) + 1
	return res // 2

def main():
	samples = read_one_int()
	for _ in range(samples):
		(a, b, k) = read_list_of_ints()
		a_lst = read_list_of_ints()
		b_lst = read_list_of_ints()
		cur_res = check_seq(k, a_lst, b_lst)
		print(cur_res)
main()


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	(f, s) = ([0 for i in range(a + 1)], [0 for i in range(b + 1)])
	ans = 0
	for i in range(k):
		f[n[i]] += 1
		s[m[i]] += 1
	for i in range(k):
		f[n[i]] -= 1
		s[m[i]] -= 1
		ans += k - i - 1 - f[n[i]] - s[m[i]]
	print(ans)


import math
from collections import Counter

def pairs(num, boys, girls):
	possible = num * (num - 1) // 2
	countB = Counter(boys)
	countG = Counter(girls)
	for (key, val) in countB.items():
		if val > 1:
			possible -= val * (val - 1) // 2
	for (key, val) in countG.items():
		if val > 1:
			possible -= val * (val - 1) // 2
	return possible
num_tests = int(input())
for i in range(num_tests):
	(a, b, k) = input().split()
	boys = input().split()
	girls = input().split()
	print(pairs(int(k), boys, girls))


from typing import List
from collections import defaultdict

def solve(inp, a, b, k):
	deg_a = [0] * (a + 1)
	deg_b = [0] * (b + 1)
	for (x, y) in inp:
		deg_a[x] += 1
		deg_b[y] += 1
	total = 0
	for (x, y) in inp:
		total += k - deg_a[x] - deg_b[y] + 1
	return total // 2

def main():
	t = int(input())
	for testcase in range(t):
		(a, b, k) = list(map(int, input().strip().split(' ')))
		a_list = list(map(int, input().strip().split(' ')))
		b_list = list(map(int, input().strip().split(' ')))
		a_b_pair = list(zip(a_list, b_list))
		answer = solve(a_b_pair, a, b, k)
		print(answer)
main()


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	bs = [int(x) for x in input().split()]
	gs = [int(x) for x in input().split()]
	b_pair_count = {}
	g_pair_count = {}
	for bi in bs:
		b_pair_count[bi] = b_pair_count.get(bi, 0) + 1
	for gi in gs:
		g_pair_count[gi] = g_pair_count.get(gi, 0) + 1
	total = 0
	for i in range(k):
		delta = k - (b_pair_count[bs[i]] + g_pair_count[gs[i]] - 1)
		total += delta
	print(total // 2)


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

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(a, b, k) = inputnums()
	x = inputlist()
	y = inputlist()
	ma = [0] * (a + 1)
	mb = [0] * (b + 1)
	for i in range(k):
		ma[x[i]] += 1
		mb[y[i]] += 1
	ans = 0
	for i in range(k):
		ans += k - ma[x[i]] - mb[y[i]] + 1
	print(ans // 2)


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	_a = list(map(int, input().split()))
	_b = list(map(int, input().split()))
	(a_c, b_c) = ([0 for i in range(a + 1)], [0 for i in range(b + 1)])
	for i in range(k):
		a_c[_a[i]] += 1
		b_c[_b[i]] += 1
	ans = 0
	for i in range(k):
		ans += k - (a_c[_a[i]] + b_c[_b[i]] - 1)
	print(ans // 2)


for _ in range(int(input())):
	(a, b, k) = list(map(int, input().split()))
	boy = list(map(int, input().split()))
	girl = list(map(int, input().split()))
	bb = [0] * (a + 1)
	gg = [0] * (b + 1)
	s = 0
	for i in range(1, k):
		bb[boy[i - 1]] += 1
		gg[girl[i - 1]] += 1
		s += i - bb[boy[i]] - gg[girl[i]]
	print(s)


import math

def ncr(n, r):
	p = 1
	k = 1
	if n - r < r:
		r = n - r
	if r != 0:
		while r > 0:
			p *= n
			k *= r
			m = math.gcd(p, k)
			p //= m
			k //= m
			n -= 1
			r -= 1
	else:
		p = 1
	return p
ans = []
t = int(input())
for _ in range(t):
	(a, b, k) = list(map(int, input().split()))
	va = list(map(int, input().split()))
	vb = list(map(int, input().split()))
	ma = dict()
	mb = dict()
	vc = []
	anss = 0
	if k < 2:
		ans.append(0)
		continue
	for i in range(k):
		if va[i] not in ma.keys():
			ma[va[i]] = 1
		else:
			ma[va[i]] += 1
	for i in range(k):
		if vb[i] not in mb.keys():
			mb[vb[i]] = 1
		else:
			mb[vb[i]] += 1
	for i in range(k):
		vc.append([va[i], vb[i]])
	for i in range(k):
		ca = vc[i][0]
		cb = vc[i][1]
		anss += k - ma[ca] - mb[cb] + 1
	ans.append(anss // 2)
for an in ans:
	print(an)


import math
from collections import Counter
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	boy = list(map(int, input().split()))
	girl = list(map(int, input().split()))
	cnt = k * (k - 1) // 2
	boy = Counter(boy)
	girl = Counter(girl)
	for i in boy:
		if boy[i] > 1:
			k = boy[i]
			cnt -= k * (k - 1) // 2
	for i in girl:
		if girl[i] > 1:
			k = girl[i]
			cnt -= k * (k - 1) // 2
	print(cnt)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	b = list(map(int, input().split()))
	g = list(map(int, input().split()))
	bb = [0] * (n + 1)
	gg = [0] * (m + 1)
	for i in range(k):
		bb[b[i]] += 1
		gg[g[i]] += 1
	ans = 0
	for i in range(k):
		ans += k - bb[b[i]] - gg[g[i]] + 1
	print(int(ans / 2))


import math

def col(m):
	return m * (m - 1) // 2
t = int(input().strip())
for _ in range(t):
	[a, b, k] = list(map(int, input().strip().split()))
	boys = list(map(int, input().strip().split()))
	girls = list(map(int, input().strip().split()))
	dick_boys = {}
	pussy_girls = {}
	for (ind, item) in enumerate(boys):
		dick_boys[item] = dick_boys.get(item, 0) + 1
	for (ind, item) in enumerate(girls):
		pussy_girls[item] = pussy_girls.get(item, 0) + 1
	total = col(k)
	boys_rem = 0
	girls_rem = 0
	for key in dick_boys:
		if dick_boys[key] > 1:
			boys_rem = boys_rem + col(dick_boys[key])
	for key in pussy_girls:
		if pussy_girls[key] > 1:
			girls_rem = girls_rem + col(pussy_girls[key])
	print(total - boys_rem - girls_rem)


from math import factorial
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	boys_dict = dict()
	girls_dict = dict()
	for i in boys:
		boys_dict[i] = boys_dict.get(i, 0) + 1
	for i in girls:
		girls_dict[i] = girls_dict.get(i, 0) + 1
	res = 0
	for (i, j) in zip(boys, girls):
		res += k - boys_dict[i] - girls_dict[j] + 1
	print(res // 2)


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

def solution(a, b, k, boys, girls):
	c_boys = Counter(boys)
	c_girls = Counter(girls)
	sol = 0
	for (b, g) in zip(boys, girls):
		sol += k - c_boys[b] - c_girls[g] + 1
	sol = sol // 2
	print(sol)
T = int(input())
for t in range(T):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	solution(a, b, k, boys, girls)


answers = []

def solve(arr1, arr2):
	store1 = {}
	store2 = {}
	for ele in arr1:
		if ele not in store1:
			store1[ele] = 1
		else:
			store1[ele] += 1
	for ele in arr2:
		if ele not in store2:
			store2[ele] = 1
		else:
			store2[ele] += 1
	total = 0
	length = len(arr1)
	for i in range(length):
		temp = store2[arr2[i]] + store1[arr1[i]] - 2
		store2[arr2[i]] -= 1
		store1[arr1[i]] -= 1
		ans = length - 1 - i - temp
		if ans > 0:
			total += ans
	answers.append(total)
t = int(input())
while t:
	(a, b, k) = [int(x) for x in input().split()]
	arr1 = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	solve(arr1, arr2)
	t -= 1
for ans in answers:
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, k) = tuple(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	dct = {}
	dct1 = {}
	for i in range(k):
		if l1[i] in dct:
			dct[l1[i]] += 1
		else:
			dct[l1[i]] = 1
		if l2[i] in dct1:
			dct1[l2[i]] += 1
		else:
			dct1[l2[i]] = 1
	total = k * (k - 1) // 2
	count = 0
	count1 = 0
	for val in dct.values():
		count += val * (val - 1) // 2
	for val in dct1.values():
		count1 += val * (val - 1) // 2
	print(total - (count + count1))


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

def solve():
	(A, B, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	x = Counter(a)
	y = Counter(b)
	ans = k * (k - 1) // 2
	for z in x:
		ans -= x[z] * (x[z] - 1) // 2
	for z in y:
		ans -= y[z] * (y[z] - 1) // 2
	return ans
t = int(input())
for _ in range(t):
	print(solve())


def solve(a, b, k, arr1, arr2):
	num1 = [0 for i in range(a)]
	num2 = [0 for i in range(b)]
	for i in range(k):
		num1[arr1[i] - 1] += 1
		num2[arr2[i] - 1] += 1
	ans = k * k
	for x in num1:
		ans -= x * x
	ans //= 2
	for x in num2:
		ans -= x * (x - 1) // 2
	return ans
t = int(input())
for i in range(t):
	(a, b, k) = map(int, input().split())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	print(solve(a, b, k, arr1, arr2))


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	A = [0] * (a + 1)
	B = [0] * (b + 1)
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	for i in x:
		A[i] += 1
	for j in y:
		B[j] += 1
	ans = 0
	for i in range(k):
		ans += k - A[x[i]] - B[y[i]] + 1
	print(ans // 2)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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 SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(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 SegmentTree1:

	def __init__(self, data, default=10 ** 6, 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)
MOD = 10 ** 9 + 7

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
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(50001)]
pp = []

def SieveOfEratosthenes(n=50000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for i in range(50001):
		if prime[i]:
			pp.append(i)
for _ in range(int(input())):
	(x, y, k) = map(int, input().split())
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	s = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(k):
		s.append((a[i], b[i]))
		d1[a[i]] += 1
		d2[b[i]] += 1
	res = 0
	for i in s:
		res += k - d1[i[0]] - d2[i[1]] + 1
	res //= 2
	print(res)


def total_2_pairs(n_boys, n_girls, total_couples, boys, girls):
	boy_pair_count = {}
	girl_pair_count = {}
	for boy in boys:
		if boy in boy_pair_count:
			boy_pair_count[boy] += 1
		else:
			boy_pair_count[boy] = 1
	for girl in girls:
		if girl in girl_pair_count:
			girl_pair_count[girl] += 1
		else:
			girl_pair_count[girl] = 1
	possible_pairs = 0
	for i in range(total_couples):
		total_pairs_with_ith_couple = total_couples - (boy_pair_count[boys[i]] + girl_pair_count[girls[i]] - 1)
		possible_pairs += total_pairs_with_ith_couple
	possible_pairs /= 2
	return int(possible_pairs)

def main():
	t = int(input().strip())
	for i in range(t):
		(n_boys, n_girls, total_couples) = list(map(int, input().strip().split()))
		boys = list(map(int, input().strip().split()))
		girls = list(map(int, input().strip().split()))
		print(total_2_pairs(n_boys, n_girls, total_couples, boys, girls))
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cntB = [0] * n
	cntG = [0] * m
	u = list(map(int, input().split()))
	v = list(map(int, input().split()))
	for i in u:
		cntB[i - 1] += 1
	for i in v:
		cntG[i - 1] += 1
	res = 0
	for i in range(k):
		res += k - cntB[u[i] - 1] - cntG[v[i] - 1] + 1
	print(res // 2)


from collections import Counter
for _ in range(int(input())):
	(a, b, k) = list(map(int, input().split()))
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	c_b = Counter(boys)
	c_g = Counter(girls)
	res = 0
	for (x, y) in zip(boys, girls):
		res += k - c_b[x] - c_g[y] + 1
	print(res // 2)


test = int(input())
while test:
	(a, b, k) = map(int, input().split())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	posa = [0 for i in range(a + 1)]
	posb = [0 for i in range(b + 1)]
	for i in li1:
		posa[i] += 1
	for i in li2:
		posb[i] += 1
	ans = 0
	for i in range(k):
		ans += k - posa[li1[i]] - posb[li2[i]] + 1
	print(ans // 2)
	test -= 1


def C(u, d):
	a = b = 1
	for i in range(1, d + 1):
		a *= u - i + 1
		b *= i
	return a // b
n = int(input())
inlist = []
boy = []
girl = []
boylist = []
girllist = []
k = []
for i in range(n):
	inlist = [int(num) for num in input().split()]
	boy = [int(num) for num in input().split()]
	girl = [int(num) for num in input().split()]
	a = [0] * (inlist[0] + 1)
	b = [0] * (inlist[1] + 1)
	k.append(inlist[2])
	for j in boy:
		a[j] += 1
	boylist.append(a)
	for j in girl:
		b[j] += 1
	girllist.append(b)
ans = []
for (i, j, l) in zip(boylist, girllist, k):
	sumnum = C(l, 2)
	mine = 0
	for a in i:
		if a > 1:
			mine += C(a, 2)
	for b in j:
		if b > 1:
			mine += C(b, 2)
	ans.append(sumnum - mine)
for i in ans:
	print(i)


import math as mt
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	graphBoys = {}
	graphGirls = {}
	for i in l:
		if graphBoys.get(i):
			graphBoys[i] += 1
		else:
			graphBoys[i] = 1
	for i in m:
		if graphGirls.get(i):
			graphGirls[i] += 1
		else:
			graphGirls[i] = 1
	totality = sum(graphBoys.values())
	cost = 0
	for i in range(k):
		thisSum = totality - graphBoys[l[i]]
		thisSum = thisSum - (graphGirls[m[i]] - 1)
		cost += thisSum
	print(mt.ceil(cost / 2))


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	b = list(map(int, input().split()))
	g = list(map(int, input().split()))
	(bo, gi) = (dict(), dict())
	for j in range(k):
		if b[j] in bo:
			bo[b[j]] += 1
		else:
			bo[b[j]] = 1
		if g[j] in gi:
			gi[g[j]] += 1
		else:
			gi[g[j]] = 1
	ans = 0
	for j in range(k):
		ans += k - bo[b[j]] - gi[g[j]] + 1
	print(ans // 2)


t = int(input())
for i in range(t):
	(a, b, k) = map(int, input().split())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	degA = [0 for i in range(a + 1)]
	degB = [0 for i in range(b + 1)]
	for i in a1:
		degA[i] += 1
	for j in b1:
		degB[j] += 1
	ans = 0
	for i in range(k):
		ans += k - degA[a1[i]] - degB[b1[i]] + 1
	print(ans // 2)


from collections import *
R = lambda : map(int, input().split())
(t,) = R()
f = lambda c: sum((x * x for x in Counter(c).values()))
for _ in [0] * t:
	(*_, k) = R()
	a = (*R(),)
	b = (*R(),)
	print(k * k - f(a) - f(b) + f(zip(a, b)) >> 1)


import sys
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

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

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

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

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
uu = t
while t > 0:
	t -= 1
	(a, b, n) = mi()
	c = {}
	d = {}
	e = {}
	a = li()
	b = li()
	for i in range(n):
		inc(c, (a[i], b[i]))
		inc(d, a[i])
		inc(e, b[i])
	ans = 0
	for i in range(n):
		ans += n - 1 - (d[a[i]] + e[b[i]] - c[a[i], b[i]] - 1)
	print(ans // 2)


from collections import *

def main():
	t = int(input())
	for _ in range(t):
		(a, b, k) = map(int, input().split())
		boys = list(map(int, input().split()))
		girls = list(map(int, input().split()))
		cntBoys = Counter(boys)
		cntGirls = Counter(girls)
		ans = 0
		for i in range(k):
			ans += k - cntBoys[boys[i]] - cntGirls[girls[i]] + 1
		print(ans // 2)
main()


from collections import defaultdict, Counter
res = []
for test in range(int(input())):
	(a, b, k) = map(int, input().split())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	cnta = Counter(al)
	cntb = Counter(bl)
	n = k * (k - 1) // 2
	s = 0
	for (i, c) in cnta.items():
		if c > 1:
			s += c * (c - 1) // 2
	for (i, c) in cntb.items():
		if c > 1:
			s += c * (c - 1) // 2
	res.append(n - s)
for ans in res:
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	degree_boys = [0] * (a + 1)
	degree_girls = [0] * (b + 1)
	for i in boys:
		degree_boys[i] += 1
	for i in girls:
		degree_girls[i] += 1
	total = 0
	for i in range(k):
		total += k - 1 - degree_boys[boys[i]] - degree_girls[girls[i]] + 2
	print(total // 2)


import math
for t in range(int(input())):
	(a, b, k) = map(int, input().split())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	store1 = [0 for i in range(a + 1)]
	store2 = [0 for i in range(b + 1)]
	for i in A:
		store1[i] += 1
	for i in B:
		store2[i] += 1
	ans = k * (k - 1) // 2
	for i in store1:
		ans -= i * (i - 1) // 2
	for i in store2:
		ans -= i * (i - 1) // 2
	print(ans)


from collections import Counter

def cal(n):
	return n * (n - 1) // 2
for i in range(int(input())):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	k = list(Counter(b).values())
	l = list(Counter(c).values())
	b = 0
	g = 0
	for i in k:
		if i >= 2:
			b = b + cal(i)
	for i in l:
		if i >= 2:
			g = g + cal(i)
	print(cal(a[2]) - (b + g))


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import copy

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, m, k) = get_ints()
	a = get_array()
	b = get_array()
	d = defaultdict(int)
	d1 = defaultdict(int)
	for i in a:
		d[i] += 1
	for i in b:
		d1[i] += 1
	ans = 0
	for i in range(k):
		max_pos = k - i - d[a[i]] - d1[b[i]] + 1
		ans += max_pos
		d[a[i]] -= 1
		d1[b[i]] -= 1
	print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from collections import defaultdict

def gift():
	for _ in range(t):
		(a, b, k) = list(map(int, input().split()))
		boys = list(map(int, input().split()))
		girls = list(map(int, input().split()))
		boydic = defaultdict(list)
		girldic = defaultdict(list)
		for i in range(k):
			(boy, girl) = (boys[i], girls[i])
			boydic[boy].append(girl)
			girldic[girl].append(boy)
		ans = 0
		for i in range(k):
			boyRelated = len(boydic[boys[i]])
			girlRelated = len(girldic[girls[i]])
			ans += max(0, k - boyRelated - girlRelated + 1)
		yield (ans // 2)
t = int(input())
ans = gift()
print(*ans, sep='\n')


for t in range(0, int(input())):
	(a, b, k) = tuple(map(int, input().split()))
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	if a == 1 or b == 1:
		print(0)
	else:
		ans = 0
		(x1, y1) = ({}, {})
		for (i, j) in zip(x, y):
			if i not in x1:
				x1[i] = 1
			else:
				x1[i] += 1
			if j not in y1:
				y1[j] = 1
			else:
				y1[j] += 1
		for (i, j) in zip(x, y):
			ans = ans + k - x1[i] - y1[j]
		ans += k
		print(ans // 2)


def solve():
	(a, b, k) = map(int, input().split())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	bd = {}
	gd = {}
	for i in range(k):
		(dil, dol) = (x[i], y[i])
		if dil in bd:
			bd[dil] += 1
		else:
			bd[dil] = 1
		if dol in gd:
			gd[dol] += 1
		else:
			gd[dol] = 1
	res = k * k
	for i in range(k):
		res -= bd[x[i]] + gd[y[i]] - 1
	return res // 2

def main():
	for _ in range(int(input())):
		print(solve())
main()


import sys
input = sys.stdin.readline
te = int(input())
while te > 0:
	(a, b, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	d1 = {}
	for i in l1:
		d1[i] = d1.get(i, 0) + 1
	d2 = {}
	for i in l2:
		d2[i] = d2.get(i, 0) + 1
	ans = k * (k - 1) // 2
	for i in d1.values():
		if i >= 2:
			ans -= i * (i - 1) // 2
	for i in d2.values():
		if i >= 2:
			ans -= i * (i - 1) // 2
	print(ans)
	te -= 1


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	m = list(map(int, input().split()))
	n = list(map(int, input().split()))
	p = [0] * a
	q = [0] * b
	for i in m:
		p[i - 1] += 1
	for i in n:
		q[i - 1] += 1
	ans = k * (k - 1) // 2
	for i in p:
		ans -= i * (i - 1) // 2
	for i in q:
		ans -= i * (i - 1) // 2
	print(ans)


import math
import sys
from collections import *
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
ans = []
for i in range(t):
	(bn, gn, k) = inlt()
	b = inlt()
	g = inlt()
	bs = Counter(b)
	gs = Counter(g)
	ret = 0
	for i in range(k):
		ret += k - bs[b[i]] - gs[g[i]] + 1
	ans.append(ret)
for r in ans:
	print(r // 2)


from collections import defaultdict
t = int(input())
for i in range(t):
	(a, b, k) = map(int, input().split(' '))
	pairs = []
	first = []
	second = []
	first = list(map(int, input().split(' ')))
	second = list(map(int, input().split(' ')))
	if a == 1 or b == 1 or k < 2:
		print(0)
	else:
		for i in range(k):
			pairs.append([first[i], second[i]])
		dict1 = defaultdict(list)
		dict2 = defaultdict(list)
		for i in range(len(pairs)):
			if pairs[i][0] not in dict1.keys():
				dict1[pairs[i][0]].append(pairs[i])
			else:
				dict1[pairs[i][0]].append(pairs[i])
			if pairs[i][1] not in dict2.keys():
				dict2[pairs[i][1]].append(pairs[i])
			else:
				dict2[pairs[i][1]].append(pairs[i])
		res = 0
		for i in range(len(pairs)):
			f = pairs[i][0]
			s = pairs[i][1]
			res += k - len(dict1[f]) - len(dict2[s]) + 1
		res /= 2
		print(int(res))


import math
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	g = [int(x) for x in input().split()]
	d = {}
	lp = [0] * a
	lg = [0] * b
	ans = 0
	for i in range(k):
		lp[l[i] - 1] += 1
	for i in range(k):
		lg[g[i] - 1] += 1
	for i in range(k):
		ans += k - lp[l[i] - 1] - lg[g[i] - 1] + 1
	print(ans // 2)


t = int(input())
for i in range(t):
	(a, b, k) = map(int, input().split())
	a_i = [0] * a
	b_i = [0] * b
	cur_a = list(map(int, input().split()))
	for j in cur_a:
		a_i[j - 1] += 1
	cur_b = list(map(int, input().split()))
	for j in cur_b:
		b_i[j - 1] += 1
	ans = k * (k - 1) // 2
	for j in a_i:
		ans -= j * (j - 1) // 2
	for j in b_i:
		ans -= j * (j - 1) // 2
	print(ans)


import math

def input_int():
	return int(input())

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

def input_list_int():
	return list(map(int, input_list()))

def z_func(s):
	n = len(s)
	z = [0] * n
	l = r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 1
	return z

def solve():
	(an, bn, k) = input_list_int()
	a = input_list_int()
	b = input_list_int()
	tmp1 = {}
	tmp2 = {}
	for i in range(k):
		if a[i] not in tmp1:
			tmp1[a[i]] = 0
		if b[i] not in tmp2:
			tmp2[b[i]] = 0
		tmp1[a[i]] += 1
		tmp2[b[i]] += 1
	ans = 0
	for i in range(k):
		v = k - max(tmp1[a[i]] + tmp2[b[i]] - 1, 0)
		ans += v
	print(ans // 2)
query_count = 1
query_count = input_int()
while query_count:
	query_count -= 1
	solve()


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			(la, lb, k) = invr()
			a = inlt()
			b = inlt()
			da = {}
			db = {}
			for i in range(k):
				if a[i] not in da:
					da[a[i]] = 0
				if b[i] not in db:
					db[b[i]] = 0
				da[a[i]] += 1
				db[b[i]] += 1
			ans = 0
			for i in range(k):
				ans += k - da[a[i]] - db[b[i]] + 1 - i
				da[a[i]] -= 1
				db[b[i]] -= 1
			print(ans)
	except Exception as e:
		print(e)
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, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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 main():
	t = int(input())
	for i in range(t):
		(a, b, k) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		ans = k * (k - 1) // 2
		da = collections.Counter(a)
		db = collections.Counter(b)
		repeat = 0
		for k in da.keys():
			if da[k] > 1:
				repeat += da[k] * (da[k] - 1) // 2
		for k in db.keys():
			if db[k] > 1:
				repeat += db[k] * (db[k] - 1) // 2
		print(ans - repeat)
main()


import sys
from collections import Counter

def rl():
	return sys.stdin.readline().strip()

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	(a, b, k) = [int(x) for x in rl().split(' ')]
	ainds = [int(x) for x in rl().split(' ')]
	binds = [int(x) for x in rl().split(' ')]
	afreq = Counter(ainds)
	bfreq = Counter(binds)
	total_pairs = 0
	for i in range(k):
		(ai, bi) = (ainds[i], binds[i])
		total_pairs += k - afreq[ai] - bfreq[bi] + 1
	pr(total_pairs // 2)


t = int(input())
for i in range(t):
	(a, b, k) = input().split()
	a = int(a)
	b = int(b)
	k = int(k)
	aa = [int(s) for s in input().split()]
	bb = [int(s) for s in input().split()]
	d = dict([])
	e = dict([])
	ans = k * (k - 1) / 2
	for j in range(k):
		if aa[j] in d:
			d[aa[j]] += 1
		else:
			d[aa[j]] = 1
		if bb[j] in e:
			e[bb[j]] += 1
		else:
			e[bb[j]] = 1
	for j in d:
		ans -= d[j] * (d[j] - 1) / 2
	for j in e:
		ans -= e[j] * (e[j] - 1) / 2
	print(int(ans))


def solve():
	inp = input().rstrip().split(' ')
	(a, b, k) = (int(inp[0]), int(inp[1]), int(inp[2]))
	arr1 = input().rstrip().split(' ')
	arr2 = input().rstrip().split(' ')
	bmap = {}
	gmap = {}
	ans = 0
	for i in range(k):
		arr1[i] = int(arr1[i])
		arr2[i] = int(arr2[i])
		if arr1[i] not in bmap:
			bmap[arr1[i]] = 0
		if arr2[i] not in gmap:
			gmap[arr2[i]] = 0
		ans += i - (bmap[arr1[i]] + gmap[arr2[i]])
		bmap[arr1[i]] += 1
		gmap[arr2[i]] += 1
	print(ans)

def main():
	T = int(input())
	for c in range(T):
		solve()
main()


from math import *
from collections import *

def read():
	return list(map(int, input().split(' ')))
(n,) = read()
for _ in range(n):
	(a, b, k) = read()
	boy = read()
	girl = read()
	pair = [(boy[i], girl[i]) for i in range(k)]
	if k == 1:
		print(0)
		continue
	(dic1, dic2) = (defaultdict(int), defaultdict(int))
	for (i, j) in pair:
		dic1[i] += 1
		dic2[j] += 1
	ans = 0
	for (i, j) in pair:
		ans += k - (dic1[i] + dic2[j] - 1)
	print(ans // 2)


t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort()
	B.sort()
	cur_a = 0
	cur_b = 0
	last_a = 0
	last_b = 0
	ans = (k - 1) * k // 2
	for i in range(k):
		if last_a != A[i]:
			ans -= (cur_a - 1) * cur_a // 2
			cur_a = 1
			last_a = A[i]
		else:
			cur_a += 1
		if last_b != B[i]:
			ans -= (cur_b - 1) * cur_b // 2
			cur_b = 1
			last_b = B[i]
		else:
			cur_b += 1
		if i == k - 1:
			ans -= (cur_a - 1) * cur_a // 2
			ans -= (cur_b - 1) * cur_b // 2
	print(ans)


import math
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque

def f(a, b, k, ai, bi):
	ans = k * (k - 1) // 2
	numa = [0 for i in range(a + 1)]
	numb = [0 for i in range(b + 1)]
	for i in range(k):
		numa[ai[i]] += 1
		numb[bi[i]] += 1
	for i in range(1, a + 1):
		if numa[i] >= 2:
			ans -= numa[i] * (numa[i] - 1) // 2
	for i in range(1, b + 1):
		if numb[i] >= 2:
			ans -= numb[i] * (numb[i] - 1) // 2
	return ans
t = int(input())
result = []
for i in range(t):
	(a, b, k) = list(map(int, input().split()))
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	result.append(f(a, b, k, ai, bi))
for i in range(t):
	print(result[i])


for _ in range(int(input())):
	(A, B, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [(i, j) for (i, j) in zip(a, b)]
	ans = k * (k - 1) // 2
	acnt = {}
	bcnt = {}
	for i in range(k):
		if a[i] in acnt:
			acnt[a[i]] += 1
		else:
			acnt[a[i]] = 1
	for i in range(k):
		if b[i] in bcnt:
			bcnt[b[i]] += 1
		else:
			bcnt[b[i]] = 1
	for i in acnt:
		if acnt[i] > 1:
			ans -= acnt[i] * (acnt[i] - 1) // 2
	for i in bcnt:
		if bcnt[i] > 1:
			ans -= bcnt[i] * (bcnt[i] - 1) // 2
	print(ans)


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	pairs1 = list(map(int, input().split()))
	pairs2 = list(map(int, input().split()))
	deg1 = [0] * (a + 1)
	deg2 = [0] * (b + 1)
	for x in pairs1:
		deg1[x] += 1
	for x in pairs2:
		deg2[x] += 1
	result = 0
	for i in range(k):
		result += k - deg1[pairs1[i]] - deg2[pairs2[i]] + 1
	print(result // 2)


import sys
import math
import bisect
import functools
from functools import lru_cache
from sys import stdin, stdout
from math import gcd, floor, sqrt, log, ceil
from heapq import heappush, heappop, heapify
from collections import defaultdict as dd
from collections import Counter as cc
from bisect import bisect_left as bl
from bisect import bisect_right as br

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
sys.setrecursionlimit(100000000)
intinp = lambda : int(input().strip())
stripinp = lambda : input().strip()
fltarr = lambda : list(map(float, input().strip().split()))
intarr = lambda : list(map(int, input().strip().split()))
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
MOD = 1000000007
num_cases = intinp()
for _ in range(num_cases):
	(a, b, k) = intarr()
	boy = intarr()
	girl = intarr()
	b = cc()
	g = cc()
	ans = 0
	for (i, j) in zip(boy, girl):
		b[i] += 1
		g[j] += 1
	for (i, j) in zip(boy, girl):
		ans += k - (b[i] + g[j] - 1)
	print(ans // 2)


from collections import Counter
remaing_test_cases = int(input())
while remaing_test_cases > 0:
	(A, B, K) = map(int, input().split())
	boys_pair = list(map(int, input().split()))
	girls_pair = list(map(int, input().split()))
	if K < 2:
		print('0')
	else:
		nc2 = K * (K - 1) // 2
		a = Counter(boys_pair)
		for i in a.keys():
			if a[i] > 1:
				k1 = a[i]
				nc2 = nc2 - k1 * (k1 - 1) // 2
		a2 = Counter(girls_pair)
		for i in a2.keys():
			if a2[i] > 1:
				k1 = a2[i]
				nc2 = nc2 - k1 * (k1 - 1) // 2
		print(nc2)
	remaing_test_cases = remaing_test_cases - 1


t = int(input())
for _ in range(t):
	(a, b, k) = list(map(int, input().split()))
	a_list = list(map(int, input().split()))
	b_list = list(map(int, input().split()))
	a_b = list(zip(a_list, b_list))
	total = k * (k - 1) // 2
	(a_clashes, b_clashes) = ([[] for _ in range(a)], [[] for _ in range(b)])
	for (idx, (x, y)) in enumerate(a_b):
		a_clashes[x - 1].append(idx)
		b_clashes[y - 1].append(idx)
	for clash in a_clashes + b_clashes:
		ln = len(clash)
		total -= ln * (ln - 1) // 2
	print(total)


import sys
input = sys.stdin.readline
from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	da = defaultdict(int)
	for i in a:
		da[i] += 1
	db = defaultdict(int)
	for i in b:
		db[i] += 1
	ans = k * (k - 1) // 2
	for v in da.values():
		ans -= v * (v - 1) // 2
	for v in db.values():
		ans -= v * (v - 1) // 2
	print(ans)


def solve(boy, girl, k, a, b):
	count = 0
	degBoy = [0 for i in range(a)]
	degGirl = [0 for i in range(b)]
	for x in boy:
		degBoy[x - 1] += 1
	for x in girl:
		degGirl[x - 1] += 1
	for i in range(k):
		temp = k - degBoy[boy[i] - 1] - degGirl[girl[i] - 1] + 1
		count += temp
	return count // 2
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	boy = list(map(int, input().split()))
	girl = list(map(int, input().split()))
	print(solve(boy, girl, k, a, b))


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

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])
for _ in range(int(input())):
	ans = 0
	(a, b, k) = LI()
	x = LI_()
	y = LI_()
	pm = [set() for i in range(a)]
	pf = [set() for i in range(b)]
	for i in range(k):
		(m, f) = (x[i], y[i])
		pm[m].add(f)
		pf[f].add(m)
	for m in range(a):
		for f in pm[m]:
			ans += k - (len(pf[f]) + len(pm[m]) - 1)
	print(ans // 2)


t = int(input())
res = []
for i in range(t):
	cnt = 0
	l = []
	(a, b, k) = map(int, input().split())
	boys = list(map(int, input().split()))
	girls = list(map(int, input().split()))
	if k == 1:
		res.append(0)
	else:
		bl = [0] * (a + 1)
		gl = [0] * (b + 1)
		for i in range(k):
			bl[boys[i]] += 1
			gl[girls[i]] += 1
		for i in range(k):
			cnt += k - bl[boys[i]] - gl[girls[i]] + 1
		res.append(cnt)
for i in res:
	print(i // 2)


import sys

def answer(a, b, k, B, G):
	Bcnt = [0 for i in range(a + 1)]
	for e in B:
		Bcnt[e] += 1
	Gcnt = [0 for i in range(b + 1)]
	for e in G:
		Gcnt[e] += 1
	summ = 0
	for i in range(len(B)):
		summ += k - Bcnt[B[i]] - Gcnt[G[i]] + 1
	return summ // 2

def main():
	t = int(sys.stdin.readline())
	while t:
		(a, b, k) = map(int, sys.stdin.readline().split())
		B = tuple(map(int, sys.stdin.readline().split()))
		G = tuple(map(int, sys.stdin.readline().split()))
		print(answer(a, b, k, B, G))
		t -= 1
	return
main()


for _ in range(int(input())):
	infos = list(map(int, input().strip().split(' ')))
	boys = infos[0]
	girls = infos[1]
	pairs = infos[2]
	b_n = list(map(int, input().strip().split(' ')))
	g_n = list(map(int, input().strip().split(' ')))
	b_record = [0] * (boys + 1)
	g_record = [0] * (girls + 1)
	for i in range(pairs):
		b_record[b_n[i]] += 1
		g_record[g_n[i]] += 1
	count = 0
	for i in range(pairs):
		count += pairs - b_record[b_n[i]] - g_record[g_n[i]] + 1
	print(int(count / 2))


t = int(input())
boys = {}
girls = {}
for _ in range(t):
	(boys, girls) = ({}, {})
	(a, b, k) = map(int, input().rsplit())
	a_all = list(map(int, input().rsplit()))
	for a_i in a_all:
		if a_i in boys:
			boys[a_i] += 1
		else:
			boys[a_i] = 1
	b_all = list(map(int, input().rsplit()))
	for b_i in b_all:
		if b_i in girls:
			girls[b_i] += 1
		else:
			girls[b_i] = 1
	res = 0
	for i in range(k):
		res += boys[a_all[i]] + girls[b_all[i]]
	print(k * (k - 1) // 2 + k - res // 2)


import sys
import heapq
from collections import deque

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def factor(n, l, d):
	F = False
	for p in l:
		if n % p == 0:
			if p in d:
				d[p] += 1
			else:
				d[p] = 1
			F = True
			break
	if F:
		factor(n // p, l, d)

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
n = int(sys.stdin.readline().strip())
for j in range(n):
	AB = sys.stdin.readline().strip().split()
	a = int(AB[0])
	b = int(AB[1])
	k = int(AB[2])
	al = [0 for i in range(a)]
	bl = [0 for i in range(b)]
	ak = sys.stdin.readline().strip().split()
	bk = sys.stdin.readline().strip().split()
	for i in range(k):
		aki = int(ak[i]) - 1
		bki = int(bk[i]) - 1
		al[aki] += 1
		bl[bki] += 1
	ans = 0
	ans = k * (k - 1) // 2
	for i in range(a):
		ans -= al[i] * (al[i] - 1) // 2
	for i in range(b):
		ans -= bl[i] * (bl[i] - 1) // 2
	print(ans)


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

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
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')
mod = 10 ** 9 + 7
for i in range(inp()):
	(a, b, k) = invr()
	l = inlt()
	m = inlt()
	d1 = {}
	d2 = {}
	for i in range(k):
		if l[i] not in d1:
			d1[l[i]] = [m[i]]
		else:
			d1[l[i]].append(m[i])
		if m[i] not in d2:
			d2[m[i]] = [l[i]]
		else:
			d2[m[i]].append(l[i])
	c = 0
	for i in d1:
		x = len(d1[i])
		for j in d1[i]:
			c = c - len(d2[j]) + k - x + 1
	print(int(c / 2))


def main():
	(a, b, k) = map(int, input().split(' '))
	m1 = dict()
	m2 = dict()
	boys = input().split(' ')
	girls = input().split(' ')
	for i in range(k):
		boys[i] = int(boys[i])
		girls[i] = int(girls[i])
		if boys[i] in m1:
			m1[boys[i]] += 1
		else:
			m1[boys[i]] = 1
		if girls[i] in m2:
			m2[girls[i]] += 1
		else:
			m2[girls[i]] = 1
	ans = 0
	for i in range(k):
		cnt = k - m1[boys[i]] - m2[girls[i]] + 1
		ans += cnt
	ans = ans / 2
	ans = int(ans)
	print(ans)
t = int(input())
for i in range(t):
	main()


import sys

def readnum():
	input = sys.stdin.readline
	a = list(map(int, input().split()))
	return a

def printf(val):
	sys.stdout.write(str(val) + '\n')

def power(a, b, mod):
	if b == 1:
		return a
	if b == 0:
		return 1
	ans = power(a, b // 2, mod)
	ans *= ans
	if b % 2:
		ans *= a
	ans = ans % mod
	return ans
t = readnum()[0]

def factorial(n, start, skip, mod):
	res = start
	for i in range(1, n + 1):
		if i == skip:
			continue
		res *= i
		res = res % mod
	return res

def make_deg(l):
	deg = {}
	for i in l:
		if not i in deg:
			deg[i] = 0
		deg[i] += 1
	return deg
for _ in range(t):
	(a, b, k) = readnum()
	boys = readnum()
	girls = readnum()
	(boys_deg, girls_deg) = (make_deg(boys), make_deg(girls))
	res = 0
	for i in range(k):
		res += k - boys_deg.get(boys[i]) - girls_deg.get(girls[i]) + 1
	print(res // 2)


from collections import defaultdict, deque, Counter
for _ in range(int(input())):
	(A, B, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ac = Counter(a)
	bc = Counter(b)
	sm = 0
	for i in range(k):
		sm += k - ac[a[i]] - bc[b[i]] + 1
	print(sm // 2)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(a, b, k) = R()
	x = [0] * (a + 1)
	y = [0] * (b + 1)
	z = list(zip(L(), L()))
	for i in z:
		x[i[0]] += 1
		y[i[1]] += 1
	ans = 0
	for i in z:
		k -= 1
		x[i[0]] -= 1
		y[i[1]] -= 1
		ans += k - x[i[0]] - y[i[1]]
	print(ans)


def solve():
	(a, b, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d_male = {}
	d_female = {}
	for i in range(k):
		if a[i] not in d_male:
			d_male[a[i]] = [b[i]]
		else:
			d_male[a[i]].append(b[i])
		if b[i] not in d_female:
			d_female[b[i]] = [a[i]]
		else:
			d_female[b[i]].append(a[i])
	ans = 0
	for i in range(k):
		ans += k - 1 - len(d_male[a[i]]) - len(d_female[b[i]]) + 2
	print(ans // 2)
t = int(input())
for q in range(t):
	solve()


from collections import Counter
from sys import stderr

def dbp(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def get_int_list():
	return [int(i) for i in input().strip().split()]

def do_thing():
	(a, b, k) = get_int_list()
	alist = get_int_list()
	blist = get_int_list()
	ac = Counter(alist)
	bc = Counter(blist)
	allk = k * (k - 1)
	for i in range(k):
		allk -= ac[alist[i]] + bc[blist[i]] - 2
	return allk // 2
maxcc = int(input().strip())
for cc in range(maxcc):
	print(do_thing())


import sys
from collections import Counter
input = lambda : sys.stdin.readline().strip()

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

def li():
	return list(mi())

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input().strip()
for _ in range(ii()):
	(a, b, k) = mi()
	A = sorted(li())
	B = sorted(li())
	AC = Counter(A)
	BC = Counter(B)
	ans = 0
	for i in range(k):
		ans += k - AC[A[i]] - BC[B[i]] + 1
	print(ans // 2)


from collections import defaultdict
for _ in range(int(input().strip())):
	(n, m, k) = map(int, input().strip().split())
	b = list(map(int, input().strip().split()))
	g = list(map(int, input().strip().split()))
	bp = defaultdict(set)
	gp = defaultdict(set)
	bs = []
	for i in range(k):
		bp[b[i]].add(g[i])
		gp[g[i]].add(b[i])
	ans = 0
	for i in range(k):
		ans += k - len(bp[b[i]]) - len(gp[g[i]]) + 1
	print(ans // 2)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

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

def solve():
	res = []
	for t in range(ii()):
		(a, b, k) = mi()
		x = li()
		y = li()
		s = set()
		m1 = dd(int)
		m2 = dd(int)
		for i in range(k):
			m1[x[i]] += 1
			m2[y[i]] += 1
		ans = 0
		for i in range(k):
			rem = m1[x[i]] + m2[y[i]] - 2
			ans += k - i - rem - 1
			m1[x[i]] -= 1
			m2[y[i]] -= 1
		print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


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():
	(A, B, K) = getInts()
	A_arr = getInts()
	B_arr = getInts()
	A_count = [0] * (A + 1)
	B_count = [0] * (B + 1)
	for a in A_arr:
		A_count[a] += 1
	for b in B_arr:
		B_count[b] += 1
	ans = 0
	for i in range(K):
		(a, b) = (A_arr[i], B_arr[i])
		ans += K + 1 - A_count[a] - B_count[b]
	assert ans % 2 == 0
	return ans // 2
for _ in range(getInt()):
	print(solve())


t = int(input())
for i in range(t):
	(a, b, k) = map(int, input().split())
	arr_a = [int(x) for x in input().split()]
	arr_b = [int(x) for x in input().split()]
	d1 = {}
	d2 = {}
	for i in arr_a:
		d1[i] = d1.get(i, 0) + 1
	for i in arr_b:
		d2[i] = d2.get(i, 0) + 1
	res = 0
	for i in range(k):
		res += k - 1
		if arr_a[i] in d1:
			res -= d1[arr_a[i]] - 1
		if arr_b[i] in d2:
			res -= d2[arr_b[i]] - 1
	res = res // 2
	print(res)


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)

def charming():
	(a, b, k) = map(int, input().split())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	pair = list(zip(arr1, arr2))
	cnt_boy = [0] * (a + 1)
	cnt_girl = [0] * (b + 1)
	d = dict()
	for (i, j) in pair:
		if (i, j) not in d:
			d[i, j] = 1
		else:
			d[i, j] += 1
		cnt_boy[i] += 1
		cnt_girl[j] += 1
	res = 0
	for (i, j) in pair:
		res += k - cnt_boy[i] - cnt_girl[j]
		if (i, j) in d:
			res += d[i, j]
	print(res // 2)
for t in range(int(input())):
	charming()


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')
t = int(input())
while t > 0:
	t -= 1
	(a, b, k) = [int(x) for x in input().split()]
	boys = [int(x) for x in input().split()]
	girls = [int(x) for x in input().split()]
	same = 0
	boys.sort()
	girls.sort()
	temp1 = 1
	temp2 = 1
	for i in range(1, k):
		if boys[i] == boys[i - 1]:
			temp1 += 1
		else:
			same += temp1 * (temp1 - 1) // 2
			temp1 = 1
		if girls[i] == girls[i - 1]:
			temp2 += 1
		else:
			same += temp2 * (temp2 - 1) // 2
			temp2 = 1
	same += temp2 * (temp2 - 1) // 2
	same += temp1 * (temp1 - 1) // 2
	sys.stdout.write(str(k * (k - 1) // 2 - same) + '\n')


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	z = list(map(int, input().split()))
	y = list(map(int, input().split()))
	c = k * (k - 1) // 2
	m = sorted(z)
	n = sorted(y)
	d = 1
	e = 1
	for i in range(k - 1):
		if m[i] == m[i + 1]:
			d += 1
		else:
			c = c - d * (d - 1) // 2
			d = 1
		if n[i] == n[i + 1]:
			e += 1
		else:
			c = c - e * (e - 1) // 2
			e = 1
	if d > 1:
		c = c - d * (d - 1) // 2
	if e > 1:
		c = c - e * (e - 1) // 2
	print(c)


def lkp(l):
	r = {}
	for e in l:
		if e in r:
			r[e] += 1
		else:
			r[e] = 1
	return r
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	la_look = lkp(la)
	lb_look = lkp(lb)
	ans = 0
	for (ea, eb) in zip(la, lb):
		ans += k - la_look[ea] - lb_look[eb] + 1
	print(ans // 2)


from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from itertools import permutations as p
from bisect import bisect_left as bl, bisect_right as br
from sys import stdin, stdout
input = stdin.readline
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
lcm = lambda a, b: a * b // gcd(a, b)
mod = 1000000007
for _ in range(it()):
	(a, b, k) = mp()
	boy = list(mp())
	Girl = list(mp())
	bc = C(boy)
	gc = C(Girl)
	ans = 0
	for j in range(k):
		curboy = boy[j]
		curg = Girl[j]
		ans += k - bc[curboy] - gc[curg] + 1
	print(ans // 2)


t = int(input())
for t in range(t):
	(a, b, k) = input().split(' ')
	a = int(a)
	b = int(b)
	k = int(k)
	aux_boys = [int(x) for x in input().split(' ')]
	aux_girls = [int(x) for x in input().split(' ')]
	boys = [0] * a
	girls = [0] * b
	sol = 0
	for i in range(k):
		boys[aux_boys[i] - 1] += 1
		girls[aux_girls[i] - 1] += 1
	for i in range(k):
		sol += k - boys[aux_boys[i] - 1] - girls[aux_girls[i] - 1] + 1
	print(f'{int(sol / 2)}')


t = int(input())
for i in range(t):
	(a, b, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	map1 = [0 for i in range(a)]
	for i in arr:
		map1[i - 1] += 1
	map2 = [0 for i in range(b)]
	for i in brr:
		map2[i - 1] += 1
	count = 0
	for i in range(k):
		count += k - map1[arr[i] - 1] - map2[brr[i] - 1] + 1
	print(count // 2)


for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	cntb = [0] * (a + 1)
	cntg = [0] * (b + 1)
	for i in map(int, input().split()):
		cntb[i] += 1
	for j in map(int, input().split()):
		cntg[j] += 1
	ans = 0
	s = sum(cntb)
	for i in range(1, a + 1):
		ans += cntb[i] * (s - cntb[i])
	ans //= 2
	for i in range(1, b + 1):
		ans -= cntg[i] * (cntg[i] - 1) // 2
	print(ans)


import math
q = int(input())
linea1 = []
linea2 = []
linea3 = []
for i in range(0, q):
	linea1.append(input())
	linea2.append(input())
	linea3.append(input())
for i in range(0, q):
	valores = list(map(int, linea1[i].split()))
	boys = list(map(int, linea2[i].split()))
	girls = list(map(int, linea3[i].split()))
	k = valores[2]
	conex_boy = [0] * valores[0]
	conex_girl = [0] * valores[1]
	result = 0
	for i in range(0, k):
		conex_boy[boys[i] - 1] += 1
		conex_girl[girls[i] - 1] += 1
	for i in range(0, k):
		result += k - conex_boy[boys[i] - 1] - conex_girl[girls[i] - 1] + 1
	print(result // 2)


from collections import Counter
for _ in range(int(input())):
	(a, b, k) = map(int, input().split())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	ac = Counter(a1)
	bc = Counter(b1)
	ans = 0
	for i in range(k):
		ans += k - ac[a1[i]] - bc[b1[i]] + 1
	print(ans // 2)