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

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

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

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

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

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

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

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

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

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

m.s = d
m.x = d
g.s = d
g.u = d
g.z = d
d.z = g
a.u = m
a.r = d
a.v = g
assert g.s.z.s.txt == "d"