using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5 9");
WillReturn.Add("1 1 2 3");
WillReturn.Add("1 1 3 2");
WillReturn.Add("1 3 5 5");
WillReturn.Add("2 1 5 1");
WillReturn.Add("2 2 5 1");
WillReturn.Add("1 2 4 4");
WillReturn.Add("1 1 4 6");
WillReturn.Add("2 1 5 1");
WillReturn.Add("2 3 5 1");
//NO
//YES
//YES
//YES
}
else if (InputPattern == "Input2") {
WillReturn.Add("5 7");
WillReturn.Add("1 1 2 3");
WillReturn.Add("1 2 4 4");
WillReturn.Add("1 5 3 1");
WillReturn.Add("2 1 3 1");
WillReturn.Add("2 5 3 1");
WillReturn.Add("1 3 1 2");
WillReturn.Add("2 3 4 1");
//NO
//NO
//NO
}
else if (InputPattern == "Input3") {
WillReturn.Add("3 6");
WillReturn.Add("1 1 2 1");
WillReturn.Add("1 1 3 3");
WillReturn.Add("1 2 3 2");
WillReturn.Add("1 2 1 2");
WillReturn.Add("2 1 3 1");
WillReturn.Add("2 2 3 1");
//YES
//YES
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
SplitAct(InputList[0]);
long NodeCnt = wkArr[0];
var InsUnionFind = new UnionFind();
for (long I = 1; I <= NodeCnt; I++) {
InsUnionFind.MakeSet(I);
InsUnionFind.MakeSet(I + NodeCnt);
}
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
long Type = wkArr[0];
long X = wkArr[1];
long Y = wkArr[2];
long Z = wkArr[3];
if (Type == 1) {
if (Z % 2 == 0) {
InsUnionFind.Unite(X, Y);
InsUnionFind.Unite(X + NodeCnt, Y + NodeCnt);
}
else {
InsUnionFind.Unite(X, Y + NodeCnt);
InsUnionFind.Unite(X + NodeCnt, Y);
}
}
if (Type == 2) {
long Root1 = InsUnionFind.FindSet(X);
long Root2 = InsUnionFind.FindSet(Y);
if (Root1 == Root2) {
Console.WriteLine("YES");
}
else {
Console.WriteLine("NO");
}
}
}
}
}
#region UnionFind
// UnionFindクラス
internal class UnionFind
{
private class NodeInfoDef
{
internal long ParentNode;
internal long Rank;
}
private Dictionary<long, NodeInfoDef> mNodeInfoDict =
new Dictionary<long, NodeInfoDef>();
// 要素が1つである木を森に追加
internal void MakeSet(long pNode)
{
NodeInfoDef WillAdd = new NodeInfoDef();
WillAdd.ParentNode = pNode;
WillAdd.Rank = 0;
mNodeInfoDict[pNode] = WillAdd;
}
// 合併処理
internal void Unite(long pX, long pY)
{
long XNode = FindSet(pX);
long YNode = FindSet(pY);
long XRank = mNodeInfoDict[XNode].Rank;
long YRank = mNodeInfoDict[YNode].Rank;
if (XRank > YRank) {
mNodeInfoDict[YNode].ParentNode = XNode;
}
else {
mNodeInfoDict[XNode].ParentNode = YNode;
if (XRank == YRank) {
mNodeInfoDict[YNode].Rank++;
}
}
}
// ノードを引数として、木の根を取得
internal long FindSet(long pTargetNode)
{
// 根までの経路上のノードのList
var PathNodeList = new List<long>();
long CurrNode = pTargetNode;
while (CurrNode != mNodeInfoDict[CurrNode].ParentNode) {
PathNodeList.Add(CurrNode);
CurrNode = mNodeInfoDict[CurrNode].ParentNode;
}
// 経路圧縮 (親ポインタの付け替え)
foreach (long EachPathNode in PathNodeList) {
mNodeInfoDict[EachPathNode].ParentNode = CurrNode;
}
return CurrNode;
}
internal void DebugPrint()
{
foreach (var EachPair in mNodeInfoDict.OrderBy(pX => pX.Key)) {
Console.WriteLine("mNodeInfoDict[{0}].ParentNode={1}",
EachPair.Key, EachPair.Value.ParentNode);
}
}
}
#endregion