# include <cstdio>
# include <cstring>
# include <vector>
# include <queue>
using namespace std;
typedef pair< int , int > PII;
const int N = 703 ;
vector< PII> g[ N] ;
double dist[ N] ;
int cnt[ N] ;
bool st[ N] ;
bool check ( double mid)
{
memset ( cnt, 0 , sizeof cnt) ;
memset ( st, false , sizeof st) ;
queue< int > q;
for ( int i= 0 ; i<= 702 ; i++ )
{
q. push ( i) ;
st[ i] = true ;
}
int cntt= 0 ;
while ( ! q. empty ( ) )
{
int t= q. front ( ) ; q. pop ( ) ;
st[ t] = false ;
for ( int i= 0 ; i< ( int ) g[ t] . size ( ) ; i++ )
{
int j= g[ t] [ i] . first, w= g[ t] [ i] . second;
if ( dist[ j] < dist[ t] + w- mid)
{
dist[ j] = dist[ t] + w- mid;
cnt[ j] = cnt[ t] + 1 ;
if ( ++ cntt> 10001 ) return true ;
if ( cnt[ j] >= N) return true ;
if ( ! st[ j] )
{
st[ j] = true ;
q. push ( j) ;
}
}
}
}
return false ;
}
int main ( )
{
int n;
while ( scanf ( "%d" , & n) , n)
{
for ( int i= 0 ; i<= 702 ; i++ ) g[ i] . clear ( ) ;
for ( int i= 1 ; i<= n; i++ )
{
char s[ 1010 ] ; scanf ( "%s" , s) ;
int len= strlen ( s) ;
if ( len>= 2 )
{
int c1= ( s[ 0 ] - 'a' ) * 26 + ( s[ 1 ] - 'a' ) ;
int c2= ( s[ len- 2 ] - 'a' ) * 26 + ( s[ len- 1 ] - 'a' ) ;
g[ c1] . push_back ( ( PII) { c2, len} ) ;
}
}
if ( ! check ( 0 ) ) puts ( "No solution." ) ;
else
{
double l= 0.0 , r= 1000.0 ;
while ( r- l> 1e-4 )
{
double mid= ( l+ r) / 2 ;
if ( check ( mid) ) l= mid;
else r= mid;
}
printf ( "%.2f\n" , r) ;
}
}
return 0 ;
}