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

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

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

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

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

n.s = m
n.q = b
m.p = j
m.w = b
b.u = n
j.o = n
j.u = m
j.q = m
assert m.p.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.q: C = None
        self.txt = txt

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

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

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

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

n.s = m
n.q = b
m.p = j
m.w = b
b.u = n
j.o = n
j.u = m
j.q = m
assert m.p.q.p.txt == "j"