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

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

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

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

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

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

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

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

d.x = a
d.s = h
h.r = d
h.p = d
a.q = h
assert h.p.s.r.txt == "d"