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

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

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

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

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

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

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

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

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

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

l.p = j
j.z = l
j.o = l
m.o = n
m.q = j
m.s = l
n.o = l
n.y = l
assert n.y.p.o.p.txt == "j"