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

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

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

l = A("l")
g = B("g")
d = C("d")
a = A("a")

l.s = g
g.u = a
g.s = d
d.z = g
a.s = g
assert d.z.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

l = A("l")
g = B("g")
d = C("d")
a = A("a")

l.s = g
g.u = a
g.s = d
d.z = g
a.s = g
assert d.z.s.z.txt == "g"