#include #include #include using namespace std; typedef long long LL; const int N = 131420; int a[N], b[N]; int main() { int n, m, T; scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } for (int i = 0; i < m; ++i) { scanf("%d", b + i); } sort(a, a + n); sort(b, b + m); LL answer = 0; for (int i = n - 1, j = 0; i >= 0 && j < m && a[i] > b[j]; --i, ++j) { answer += a[i] - b[j]; } cout << answer << endl; } return 0; }