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

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

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

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

a = A("a")
m = B("m")
n = C("n")
i = D("i")

a.u = m
a.y = n
a.x = n
m.u = i
n.z = a
i.u = m
assert a.x.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.y: C = None
        self.x: C = None
        self.txt = txt

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

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

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

a = A("a")
m = B("m")
n = C("n")
i = D("i")

a.u = m
a.y = n
a.x = n
m.u = i
n.z = a
i.u = m
assert a.x.z.y.z.txt == "a"