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

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

m = A("m")
l = B("l")
j = B("j")
e = A("e")
n = A("n")
i = A("i")
f = A("f")

m.z = f
m.r = n
l.y = n
j.y = m
e.z = i
e.r = m
n.z = m
n.r = f
i.z = n
i.r = e
f.z = m
f.r = e
assert e.z.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: A = None
        self.txt = txt

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

m = A("m")
l = B("l")
j = B("j")
e = A("e")
n = A("n")
i = A("i")
f = A("f")

m.z = f
m.r = n
l.y = n
j.y = m
e.z = i
e.r = m
n.z = m
n.r = f
i.z = n
i.r = e
f.z = m
f.r = e
assert e.z.r.r.r.txt == "n"