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

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

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

c = A("c")
d = B("d")
k = C("k")

c.z = d
d.s = c
k.z = c
k.s = d
k.q = d
assert k.z.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

c = A("c")
d = B("d")
k = C("k")

c.z = d
d.s = c
k.z = c
k.s = d
k.q = d
assert k.z.z.s.txt == "c"