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

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

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

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

n = A("n")
i = B("i")
l = C("l")
h = D("h")

n.y = l
n.z = l
n.q = i
i.r = h
l.w = h
l.y = i
h.x = l
assert n.z.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.z: C = None
        self.q: B = None
        self.txt = txt

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

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

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

n = A("n")
i = B("i")
l = C("l")
h = D("h")

n.y = l
n.z = l
n.q = i
i.r = h
l.w = h
l.y = i
h.x = l
assert n.z.y.r.txt == "h"