class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: 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.w: A = None
        self.q: B = None
        self.txt = txt

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

d.z = k
d.x = h
h.z = d
k.w = d
k.q = h
assert d.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: 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.w: A = None
        self.q: B = None
        self.txt = txt

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

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