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

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

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

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

n = A("n")
j = B("j")
m = C("m")
l = D("l")

n.w = j
j.p = l
m.q = n
m.r = l
m.s = l
m.v = j
l.q = m
assert j.p.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

n = A("n")
j = B("j")
m = C("m")
l = D("l")

n.w = j
j.p = l
m.q = n
m.r = l
m.s = l
m.v = j
l.q = m
assert j.p.q.q.txt == "n"