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

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

a = A("a")
d = B("d")
j = A("j")
k = B("k")
l = A("l")

a.z = k
d.o = a
d.z = l
j.z = k
k.o = j
k.z = l
l.z = k
assert l.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

a = A("a")
d = B("d")
j = A("j")
k = B("k")
l = A("l")

a.z = k
d.o = a
d.z = l
j.z = k
k.o = j
k.z = l
l.z = k
assert l.z.z.z.txt == "k"