#include <bits/stdc++.h>
#define ll long long
using namespace std;
int t,n;
string a[105],all;
bool cmp(string x,string y) {
return x[x.size()-1]<y[0];
}
bool checker(string m){
for (int i=1;i<m.size();++i) {
if (m[i-1]>m[i]) return 0;
}
return 1;
}
int main () {
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--) {
cin>>n;
getchar();
for (int i=1;i<=n;++i) {
cin>>a[i];
getchar();
}
sort (a+1,a+n+1,cmp);
all="";
for (int i=1;i<=n;++i) all+=a[i];
if (checker(all)) cout<<1<<'\n';
else cout<<0<<'\n';
}
return 0;
}