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

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

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

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

l = A("l")
n = B("n")
d = C("d")
a = D("a")
g = C("g")

l.w = n
l.o = a
n.z = d
d.q = n
d.p = g
a.p = l
g.q = n
g.p = d
assert n.z.p.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.o: D = None
        self.txt = txt

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

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

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

l = A("l")
n = B("n")
d = C("d")
a = D("a")
g = C("g")

l.w = n
l.o = a
n.z = d
d.q = n
d.p = g
a.p = l
g.q = n
g.p = d
assert n.z.p.q.z.txt == "d"