#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;

typedef unsigned long long LL;
const int maxn = 55;
const int maxm = 100005;
const int P = (int)1e9+7;
LL pv[ maxn ];
int n;
LL h[ maxm ][ maxn ];
int len[ maxm ];
char s[ maxm ][ maxn ];

LL H(int x, int y, LL h[]) {
	return x? h[y]-h[x-1]*pv[y-x+1]:h[y];
}

void pre(){
	pv[0]=1;
	for(int i=1;i<maxn;++i) pv[i]=pv[i-1]*P;
}

LL GH(int x){
	h[x][0]=s[x][0];
	for(int i=1;s[x][i];++i)h[x][i]=h[x][i-1]*P+s[x][i];
	return h[x][len[x]-1];
}

LL v[ maxm ];
int ct;


const int sz = 1 << 20;
struct Hash{
	LL key;
	int nxt, cnt;
}hash[ sz << 1];
int fid,top;
int flg[ sz ];

void init(){
	top=sz;
	++fid;
}

void insert(LL key) {
	int s=key&(sz-1);
	if(flg[s]!=fid) {
		flg[s]=fid;
		hash[s].nxt=-1;
		hash[s].key=key;
		hash[s].cnt=1;
		return;
	}
	while(s!=-1){
		if(hash[s].key == key) {
			++hash[s].cnt;
			return ;
		}
		if(hash[s].nxt == -1) break;
		s = hash[s].nxt;
	}
	hash[s].nxt=++top;
	hash[top].nxt=-1;
	hash[top].key=key;
	hash[top].cnt = 1;
}

int jige(LL key) {
		int s=key&(sz-1);
		if(flg[s]!=fid) {
			return 0;
		}
		while(s!=-1){
			if(hash[s].key == key) {
				return hash[s].cnt;
			}
			s = hash[s].nxt;
		}
		return 0;
}
int main() {
	pre();
	while(cin>>n,n) {
		init();
		LL ans = 0;
		ct = 0;
		for(int i=0;i<n;++i) scanf("%s", s + i), len[i]=strlen(s[i]);
		for(int i=0;i<n;++i) v[ct++]=(GH(i));v[ct]=0;
		sort(v,v+ct);
		for(int i=0;i<n;++i)if(len[i]>1){
			for(int j=0;j<len[i]-1;++j){
				LL now = H(0,j,h[i]), aft = H(j+1,len[i]-1,h[i]);
				int j = lower_bound(v,v+ct,aft)-v;
				if(aft == v[j]) insert(now);
			}
		}
		for(int i=0;i<n;++i){
			for(int j=0;j<len[i]-1;++j){
				LL now = H(0,j,h[i]),aft=H(j+1,len[i]-1,h[i]);
				int j = lower_bound(v,v+ct,now)-v;
				if(now != v[j]) continue ;
				ans +=jige(aft);
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}
