n,q=gets.split
s=(?0...n).map{|v|[v]}
$<.map{|l|
c,x,y=l.split
if c[?0]
a=s.slice! s.index{|v|v.include? x}
b=s.slice! s.index{|v|v.include? y}
s<<(a|b)
else
i=s.index{|v|v.include? x}
p s[i].include?(y) ?1:0
end
}