#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n;
string s[10000];
cin>>t;
bool flag=true;
for(int i=0;i<t;i++){
cin>>n;
for(int j=0;j<n;j++){
cin>>s[j];
}
flag=true;
for(int j=0;j<n;j++){
for(int a=0;a<j;a++){
if(s[a]>s[j]){
flag=false;
cout<<0<<endl;
break;
}
}
}
if(flag=true){
cout<<1<<endl;
}
}
return 0;
}