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

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

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

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: A = None
        self.r: C = None
        self.p: A = None
        self.txt = txt

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

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

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

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

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: A = None
        self.r: C = None
        self.p: A = None
        self.txt = txt

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

d.u = m
d.r = a
a.y = m
a.p = n
m.u = d
n.z = a
n.w = d
n.p = d
n.r = m
assert d.u.u.u.u.txt == "d"