import java.util.*;

public class SofaA
{
    static int n;
    static int[][] frameTimes, upholsteryTimes;
    static int[] frameMappings, upholsteryMappings, totalTimes;

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int c = 1;
        while(true)
        {
            n = scan.nextInt();
            if(n == 0) return;

            frameTimes = new int[n][n];
            upholsteryTimes = new int[n][n];
            frameMappings = new int[n];
            upholsteryMappings = new int[n];
            totalTimes = new int[n];

            for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++)
                    frameTimes[i][j] = scan.nextInt();

            for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++)
                    upholsteryTimes[i][j] = scan.nextInt();

            System.out.println("Case " + (c++) + ":");
            solve();
        }
    }

    public static void solve()
    {
        int[][] frameTimesCopy = new int[n][n];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                frameTimesCopy[i][j] = frameTimes[i][j];

        findAssignment(frameTimesCopy, frameMappings);

        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                int personAvailableTime = frameTimes[i][frameMappings[i]];
                int frameAvailableTime = 0;
                for(int k = 0; k < n; k++)
                    if(frameMappings[k] == j)
                        frameAvailableTime = frameTimes[k][j];
                upholsteryTimes[i][j] += Math.max(personAvailableTime, frameAvailableTime);
            }
        }

        int[][] upholsteryTimesCopy = new int[n][n];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                upholsteryTimesCopy[i][j] = upholsteryTimes[i][j];

        findAssignment(upholsteryTimesCopy, upholsteryMappings);

        int totalIdleTime = 0;
        for(int i = 0; i < n; i++)
        {
            int j = upholsteryMappings[i];
            int personDoneWithFraming = frameTimes[i][frameMappings[i]];
            int sofaDoneWithFraming = 0;
            for(int k = 0; k < n; k++)
                if(frameMappings[k] == j)
                    sofaDoneWithFraming = frameTimes[k][j];

            if(personDoneWithFraming < sofaDoneWithFraming)
                totalIdleTime += (sofaDoneWithFraming - personDoneWithFraming);
        }

        for(int i = 0; i < n; i++)
            System.out.println("Worker " + (i+1) + ":" + " " + (frameMappings[i]+1) + " " + (upholsteryMappings[i]+1) + " " + (upholsteryTimes[i][upholsteryMappings[i]]));
        System.out.println("Total idle time: " + totalIdleTime);
    }

    public static void findAssignment(int[][] times, int[] mappings)
    {
        boolean[][] assignments = new boolean[n][n];
        while(true)
        {
            reduce(times);
            assignments = new boolean[n][n];
            int matches = iterate(times, assignments);
            if(matches == n)
                break;
        }

        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                if(assignments[i][j])
                    mappings[i] = j;
    }

    public static int iterate(int[][] m, boolean[][] assignments)
    {
        int numAssignments = 0;
        boolean[] assignedRows = new boolean[n];
        boolean[] assignedCols = new boolean[n];

        for(int i = 0; i < n; i++)
        {
            int numZeros = 0;
            int zeroLoc = -1;
            for(int j = 0; j < n; j++)
                if(m[i][j] == 0)
                    if(!assignedCols[j])
                    {
                        numZeros++;
                        zeroLoc = j;
                    }

            if(numZeros == 1)
            {
                assignments[i][zeroLoc] = true;
                numAssignments++;
                assignedRows[i] = true;
                assignedCols[zeroLoc] = true;
            }
        }

        for(int j = 0; j < n; j++)
        {
            int numZeros = 0;
            int zeroLoc = -1;
            for(int i = 0; i < n; i++)
                if(m[i][j] == 0)
                    if(!assignedRows[i] && !assignedCols[j])
                    {
                        numZeros++;
                        zeroLoc = i;
                    }

            if(numZeros == 1)
            {
                assignments[zeroLoc][j] = true;
                numAssignments++;
                assignedCols[j] = true;
                assignedRows[zeroLoc] = true;
            }
        }

        if(numAssignments == n)
            return n;

        boolean[] tickColumns = new boolean[n];
        boolean[] tickRows = new boolean[n];
        for(int i = 0; i < n; i++)
            tickRows[i] = !assignedRows[i];

        boolean keepGoing = true;
        while(keepGoing)
        {
            keepGoing = false;
            for(int i = 0; i < n; i++)
                if(tickRows[i])
                    for(int j = 0; j < n; j++)
                        if(m[i][j] == 0 && !tickColumns[j])
                            tickColumns[j] = true;
            for(int j = 0; j < n; j++)
                if(tickColumns[j])
                    for(int i = 0; i < n; i++)
                        if(assignments[i][j] && !tickRows[i])
                        {
                            keepGoing = true;
                            tickRows[i] = true;
                        }
        }

        int smallest = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                if(tickRows[i] && !tickColumns[j])
                    smallest = Math.min(smallest, m[i][j]);

        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                if(tickRows[i] && !tickColumns[j])
                    m[i][j] -= smallest;
                else if(!tickRows[i] && tickColumns[j])
                    m[i][j] += smallest;    

        return numAssignments;
    }

    public static void reduce(int[][] m)
    {
        for(int i = 0; i < n; i++)
        {
            int min = Integer.MAX_VALUE;
            for(int j = 0; j < n; j++)
                min = Math.min(min, m[i][j]);
            for(int j = 0; j < n; j++)
                m[i][j] -= min;
        }
        for(int i = 0; i < n; i++)
        {
            int min = Integer.MAX_VALUE;
            for(int j = 0; j < n; j++)
                min = Math.min(min, m[j][i]);
            for(int j = 0; j < n; j++)
                m[j][i] -= min;
        }
    }
}
