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

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

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

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

k.r = h
c.q = k
c.t = k
h.z = k
assert c.q.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

k.r = h
c.q = k
c.t = k
h.z = k
assert c.q.r.z.txt == "k"