#include<bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int s1, s2; cin >> s1 >> s2; int arr1[s1+1], arr2[s2+1]; for(int i = 1; i <= s1; i++)cin >> arr1[i]; for(int i = 1; i <= s2; i++)cin >> arr2[i]; sort(arr1+1, arr1+s1+1); sort(arr2+1, arr2+s2+1); long long dp[s1+1][s2+1]; for(int i = 0; i <= s1; i++){ for(int j = 0; j <= s2; j++){ dp[i][j] = 1 << 30; } } for(int i = 0; i <= s1; i++){ for(int j = 0; j <= s2; j++){ if(i == 0 && j == 0) dp[i][j] = 0; else if(j >= i){ dp[i][j] = min( dp[i][j-1], abs(arr2[j]-arr1[i])+dp[i-1][j-1] ); } } } cout << dp[s1][s2] << endl; } } /* 2 4 5 1 1 1 1 1 3 5 10 100 2 3 30 20 50 10 40 */