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

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

n = A("n")
e = B("e")
m = C("m")
b = D("b")

n.z = m
e.x = b
m.r = n
b.u = n
b.x = n
b.p = e
assert b.u.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

n = A("n")
e = B("e")
m = C("m")
b = D("b")

n.z = m
e.x = b
m.r = n
b.u = n
b.x = n
b.p = e
assert b.u.z.r.txt == "n"