R=range J=lambda:map(int,input().split()) N,*_=J() A=[[[]for i in R(N+1)]for s in R(2)] a=0 for _ in R(N): C,X,Y=J() if X