https://www.acmicpc.net/problem/7795
import sys
input = sys.stdin.readline
testCase = int(input())
for _ in range(testCase):
a, b = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr1.sort()
arr2.sort()
start = 0
cnt = 0
for i in range(a):
while True:
if start == b or arr1[i] <= arr2[start]:
cnt += start
break
else:
start += 1
print(cnt)