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

class B:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
b = C("b")
a = D("a")
f = C("f")
j = D("j")

n.u = k
n.r = k
k.w = n
b.x = n
a.u = k
a.x = n
a.y = b
f.x = n
j.u = k
j.x = n
j.y = b
assert a.u.w.u.w.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.r: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
b = C("b")
a = D("a")
f = C("f")
j = D("j")

n.u = k
n.r = k
k.w = n
b.x = n
a.u = k
a.x = n
a.y = b
f.x = n
j.u = k
j.x = n
j.y = b
assert a.u.w.u.w.u.w.txt == "n"