#include<bits/stdc++.h>
using namespace std;
int a[6];
bool check1(){
int b[11];
memset(b,0,sizeof b);
for(int i=1;i<=4;i++){
b[a[i]]++;
}
for(int i=0;i<=9;i++){
if(b[i]>=2)return true;
}
return false;
}
bool check2(){
int b[11];
memset(b,0,sizeof b);
for(int i=1;i<=4;i++){
b[a[i]]++;
}
for(int i=0;i<=9;i++){
if((b[i]>=1&&b[i+1]>=1&&(b[i]!=2&&b[i+1]!=2))||(b[i]>=1&&b[i+2]>=1&&(b[i]!=2&&b[i+1]!=2)))return true;
}
return false;
}
bool check3(){
int b[11];
memset(b,0,sizeof b);
for(int i=1;i<=4;i++){
b[a[i]]++;
}
for(int i=0;i<=9;i++){
if(b[i]>=1&&b[i+1]>=1&&b[i+2]>=1)return true;
}
return false;
}
int main(){
int n;
cin>>n;
while(n--){
for(int i=1;i<=4;i++)cin>>a[i];
if((check1()&&check2())||check3())cout<<1<<endl;
else cout<<0<<endl;
}
}