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

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

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

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

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

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

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

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

a.s = d
a.w = h
h.y = m
m.z = g
m.q = h
m.t = a
d.s = a
d.w = h
g.y = m
assert h.y.t.s.s.w.txt == "h"