#include <bits/stdtr1c++.h>
using namespace std;
const int INF = 100000000;

const int N = 51;
int w[N][N], w2[N][N], w3[N][N], ml[N], mr[N], lbl[N], lbr[N], s[N], slack[N], par[N]; // Yury's
//! Run time is O(m * n^2)
int wmatch(int n, int m){ // assume n <= m;
  int i, j, k, done, al, nxt, out = 0;
  for(i=0;i<n;i++)for(j=0,lbl[i]=0,ml[i]=-1;j<m;j++) lbl[i]=max(lbl[i],w[i][j]);
  for(i = 0; i < m; i++) lbr[i] = 0, mr[i] = -1;
  for(i=0;i<n;i++) for(j = 0; j < m; j++) if(w[i][j] == lbl[i] && mr[j] == -1)
    { ml[i] = j, mr[j] = i; break; }
  for(i = 0; i < n; i++) if(ml[i] == -1){
    for(j=0;j<m;j++) s[j]=(j==i), slack[j]=(lbl[i]+lbr[j]-w[i][j]), par[j] = -1;
    for(done = 0; !done;){
      for(j = 0, al = INF; j < m; j++) if(par[j] == -1) al = min(al, slack[j]);
      for(j = 0, lbl[j] -= s[j]*al; j < m; ++j, lbl[j] -= s[j]*al)
        if(par[j] != -1) lbr[j] += al; else slack[j] -= al;
      for(j = 0; j < m; j++) if(!slack[j] && par[j] == -1){
        for(k=0;k<n;k++) if(s[k]&&(lbl[k]+lbr[j]==w[k][j])){ par[j] = k; break;}
        if(mr[j] == -1){ done = 1;
          do{ nxt=ml[par[j]], mr[j]=par[j], ml[par[j]]=j, j=nxt;}while(j != -1);
        }else for(k = 0, s[mr[j]] = 1; k < m; k++)
          slack[k] = min(slack[k], lbl[mr[j]] + lbr[k] - w[mr[j]][k]); break;}}}
  for(i = 0; i < n; i++) out += w[i][ml[i]]; return out; }

int ans[N][3];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int csnum = 1;
    int n; cin >> n;
    while (n > 0) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> w2[i][j];
                w[i][j] = -w2[i][j];
            }
        }
        wmatch(n, n);
        for (int i = 0; i < n; i++) {
            ans[i][0] = ml[i];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> w3[i][j];
                w[i][j] = -(max(w2[i][ml[i]], w2[mr[j]][j]) + w3[i][j]);
            }
        }
        wmatch(n, n);
        for (int i = 0; i < n; i++) {
            ans[i][1] = ml[i];
            ans[i][2] = -w[i][ml[i]];
        }

        int idle = 0;
        cout << "Case " << csnum << ":" << endl;
        for (int i = 0; i < n; i++) {
            cout << "Worker " << i+1 << ": " << ans[i][0]+1 << " " << ans[i][1]+1 << " " << ans[i][2] << endl;
            idle += ans[i][2] - w2[i][ans[i][0]] - w3[i][ans[i][1]];
        }
        cout << "Total idle time: " << idle << endl;

        cin >> n;
        csnum++;
    }
}