#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
string s[105] = {};
for(int i = 1; i <= n; i++){
cin >> s[i];
}
sort(s + 1, s + 1 + n);
string t = "";
for(int i = 1; i <= n; i++) {
t += s[i];
}
bool flag = true;
for(int i = 1; i < t.size(); i++){
if(t[i] < t[i-1]){
flag = false;
}
}
if(flag) cout << 1 << endl;
else cout << 0 << endl;
}
return 0;
}