class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.y: B = None
        self.txt = txt

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

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

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

a.w = h
a.y = h
h.s = a
h.q = a
i.q = h
i.x = h
d.q = h
d.x = h
assert d.x.s.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.y: B = None
        self.txt = txt

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

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

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

a.w = h
a.y = h
h.s = a
h.q = a
i.q = h
i.x = h
d.q = h
d.x = h
assert d.x.s.y.q.txt == "a"