class A:
    def __init__(self, txt: str):
        self.s: B = 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.z: A = None
        self.txt = txt

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

m.s = h
g.u = a
a.z = m
j.z = m
h.u = a
assert j.z.s.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = 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.z: A = None
        self.txt = txt

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

m.s = h
g.u = a
a.z = m
j.z = m
h.u = a
assert j.z.s.u.txt == "a"