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

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

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

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

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

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

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

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

h.r = n
h.t = d
h.s = d
d.z = n
f.q = h
f.x = d
n.q = h
n.x = d
assert f.q.r.x.txt == "d"