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

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

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

class D:
    def __init__(self, txt: str):
        self.t: C = None
        self.w: A = None
        self.txt = txt

n = A("n")
a = B("a")
l = C("l")
j = D("j")
c = B("c")

n.r = j
n.q = a
n.x = c
n.u = l
a.y = l
l.z = a
l.p = c
j.t = l
j.w = n
c.y = l
assert j.w.x.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.q: B = None
        self.x: B = None
        self.u: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.t: C = None
        self.w: A = None
        self.txt = txt

n = A("n")
a = B("a")
l = C("l")
j = D("j")
c = B("c")

n.r = j
n.q = a
n.x = c
n.u = l
a.y = l
l.z = a
l.p = c
j.t = l
j.w = n
c.y = l
assert j.w.x.y.p.txt == "c"