class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.r: B = None
        self.txt = txt

n = A("n")
m = B("m")
i = B("i")
j = A("j")
d = B("d")
c = A("c")
b = A("b")

n.y = b
n.w = j
m.t = c
m.r = d
i.t = n
i.r = m
j.y = c
j.w = b
d.t = j
d.r = i
c.y = b
c.w = n
b.y = c
b.w = c
assert m.t.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.r: B = None
        self.txt = txt

n = A("n")
m = B("m")
i = B("i")
j = A("j")
d = B("d")
c = A("c")
b = A("b")

n.y = b
n.w = j
m.t = c
m.r = d
i.t = n
i.r = m
j.y = c
j.w = b
d.t = j
d.r = i
c.y = b
c.w = n
b.y = c
b.w = c
assert m.t.w.w.txt == "j"