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

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

i = A("i")
m = B("m")
l = B("l")
c = A("c")
b = B("b")
j = B("j")

i.z = m
i.u = m
m.t = i
l.t = i
c.z = m
c.u = l
b.t = c
j.t = i
assert m.t.z.t.z.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.u: B = None
        self.txt = txt

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

i = A("i")
m = B("m")
l = B("l")
c = A("c")
b = B("b")
j = B("j")

i.z = m
i.u = m
m.t = i
l.t = i
c.z = m
c.u = l
b.t = c
j.t = i
assert m.t.z.t.z.t.z.txt == "m"