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

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

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

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

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

j.y = k
j.z = m
m.u = j
c.q = a
c.w = a
c.p = j
a.o = c
n.q = a
n.w = a
n.p = j
k.u = j
assert c.q.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.z: B = None
        self.txt = txt

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

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

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

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

j.y = k
j.z = m
m.u = j
c.q = a
c.w = a
c.p = j
a.o = c
n.q = a
n.w = a
n.p = j
k.u = j
assert c.q.o.p.txt == "j"