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

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

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

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

d.x = k
d.w = b
b.z = d
k.q = d
k.z = d
assert k.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.w: B = None
        self.txt = txt

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

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

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

d.x = k
d.w = b
b.z = d
k.q = d
k.z = d
assert k.z.x.z.txt == "d"