#include<stdio.h>
#include<math.h>
int main()
{
	int T;
	scanf("%d",T);
	int i,N,M,A,B,r;
	
	for(i = 1; i <= T; i = i + 1)
	{
		scanf("%d %d",&N,&M);
	
	}
	for(i = 1; i <= N; i = i + 1)
	{
		scanf("%d",&A);
	}
	for(i = 1; i <= M; i = i + 1)
	{
		scanf("%d",&B);
	}
	r = abs(A - B);
	if(r == 10)printf("1");
	  else printf("0");
	  
return 0;
	  
}