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

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

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

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

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

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

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

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

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

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

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