#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,sum,ret;
	int info[10][10];
	vector<int> data;
	while(cin >> n && n){
		data.clear();
		rep(i,n)data.push_back(i);
		rep(i,10)rep(j,10)info[i][j] = 0	;
		rep(i,n)rep(j,n){
			cin >> info[i][j];
			info[j][i] = info[i][j] = max(info[i][j],info[j][i]);
		}
		rep(i,n){
			rep(j,n)cout << info[i][j] << " "	;
			cout << endl;
		}
		ret = INT_MAX;
		do{
			sum = 0;
			for(int i=0;i+1<n;i++){
				for(int i=0;i
				sum += info[data[i]][data[i+1]];
			}
			cout << "("<< data[n-1] << ") = " << sum << endl;
			ret = min(ret,sum);
		}while(next_permutation(data.begin(),data.end()));
		cout << ret << endl;
	}
}