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

class B:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

d.q = h
d.z = h
d.r = n
n.u = h
h.s = d
h.v = d
h.r = n
assert d.r.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.r: B = None
        self.z: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

d.q = h
d.z = h
d.r = n
n.u = h
h.s = d
h.v = d
h.r = n
assert d.r.u.s.txt == "d"