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

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

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

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

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

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

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

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

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

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

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