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

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

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

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

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

n.q = l
l.s = h
h.s = n
h.q = n
h.z = k
h.v = k
k.w = n
k.q = l
k.v = l
assert l.s.z.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

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

n.q = l
l.s = h
h.s = n
h.q = n
h.z = k
h.v = k
k.w = n
k.q = l
k.v = l
assert l.s.z.w.q.txt == "l"