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

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

m = A("m")
k = B("k")
n = B("n")
c = B("c")
i = A("i")
j = B("j")

m.z = i
k.s = m
k.p = m
n.s = i
n.p = m
c.s = i
c.p = i
i.z = m
j.s = m
j.p = m
assert j.p.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

m = A("m")
k = B("k")
n = B("n")
c = B("c")
i = A("i")
j = B("j")

m.z = i
k.s = m
k.p = m
n.s = i
n.p = m
c.s = i
c.p = i
i.z = m
j.s = m
j.p = m
assert j.p.z.z.z.z.z.txt == "i"