/*
Jackson Simoneau
SI@UCF 2026 - Intro to Competitive Programming
Contest 1

Solution to Miniumum Scalar Product: https://open.kattis.com/problems/minimumscalar
*/

#include <bits/stdc++.h>
using namespace std;

int main() {
    //Process test cases
    int t;
    cin >> t;
    for(int c = 1; c <= t; c++) {
        int n;
        cin >> n;
        vector<long long> a(n), b(n);
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for(int i = 0; i < n; i++) {
            cin >> b[i];
        }

        //Sort one vector forwards and the other backwards
        //This ensures that the smallest and largest values are paired to minimize the scalar product
        sort(a.begin(), a.end());
        sort(b.rbegin(), b.rend());

        //Compute the scalar product of these permutations
        //Make sure to use long longs to not overflow!
        long long res = 0;
        for(int i = 0; i < n; i++) {
            res += a[i] * b[i];
        }
        //Display the answer
        cout << "Case #" << c << ": " << res << endl;
    }
}