#include <iostream>
#include <string.h>
using namespace std;

int n, h[100][100], low, high, v[100][100];

int possible ( int i, int j ) {
  if( i<0 || i>=n || j<0 || j>=n || v[i][j] || h[i][j]<low || h[i][j]>high )
    return 0;
  v[i][j] = 1;
  return (i==n-1 && j==n-1)
    || possible( i, j+1 )
    || possible( i, j-1 )
    || possible( i+1, j )
    || possible( i-1, j );
}

int main () {
  int S;
  cin >> S;
  for( int s=1; s<=S; s++ ){
    cout << "Scenario #" << s << ":\n";
    
    cin >> n;
    for( int i=0; i<n; i++ )
      for( int j=0; j<n; j++ )
	cin >> h[i][j];
    
    int best = 200;
    for( low=0; low<=200; low++ ){
      int min = low, max = 201;
      while( min < max ){
	high = (min + max) / 2;
	memset( v, 0, sizeof( v ));
	if( possible( 0, 0 ))
	  max = high;
	else
	  min = ++high;
      }
      if( high < 201 )
	best = std::min(best, high - low);
    }
    
    cout << best << "\n\n";
  }
}
