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

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

k = A("k")
l = B("l")
c = B("c")
a = A("a")

k.z = a
l.x = k
l.w = a
c.x = k
c.w = k
a.z = k
assert k.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

k = A("k")
l = B("l")
c = B("c")
a = A("a")

k.z = a
l.x = k
l.w = a
c.x = k
c.w = k
a.z = k
assert k.z.z.z.txt == "a"