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

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

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

d = A("d")
m = B("m")
e = C("e")
c = C("c")
g = C("g")
j = B("j")
a = B("a")

d.z = c
m.r = c
e.y = d
e.x = d
e.s = d
c.y = d
c.x = d
c.s = d
g.y = d
g.x = d
g.s = d
j.r = c
a.r = g
assert j.r.x.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

d = A("d")
m = B("m")
e = C("e")
c = C("c")
g = C("g")
j = B("j")
a = B("a")

d.z = c
m.r = c
e.y = d
e.x = d
e.s = d
c.y = d
c.x = d
c.s = d
g.y = d
g.x = d
g.s = d
j.r = c
a.r = g
assert j.r.x.z.x.txt == "d"