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

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

i = A("i")
j = B("j")
d = B("d")
n = B("n")
h = A("h")
l = A("l")

i.w = l
i.z = d
j.s = l
d.s = l
n.s = l
h.w = l
h.z = d
l.w = h
l.z = d
assert j.s.z.s.w.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.z: B = None
        self.txt = txt

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

i = A("i")
j = B("j")
d = B("d")
n = B("n")
h = A("h")
l = A("l")

i.w = l
i.z = d
j.s = l
d.s = l
n.s = l
h.w = l
h.z = d
l.w = h
l.z = d
assert j.s.z.s.w.z.s.txt == "l"