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

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

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

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

m = A("m")
h = B("h")
j = C("j")
b = D("b")

m.x = h
m.z = j
h.u = j
h.r = b
j.u = b
b.y = j
b.z = j
b.x = h
b.s = m
assert h.r.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.z: C = None
        self.txt = txt

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

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

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

m = A("m")
h = B("h")
j = C("j")
b = D("b")

m.x = h
m.z = j
h.u = j
h.r = b
j.u = b
b.y = j
b.z = j
b.x = h
b.s = m
assert h.r.s.z.txt == "j"