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

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

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

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

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

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

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

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

d.p = l
l.x = c
l.s = d
c.z = g
c.s = l
g.x = c
g.s = d
assert l.s.p.x.z.txt == "g"