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

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

m = A("m")
k = B("k")
d = A("d")
g = A("g")
h = B("h")
i = B("i")
b = B("b")
l = B("l")

m.z = k
k.w = g
d.z = h
g.z = k
h.w = d
i.w = d
b.w = m
l.w = m
assert d.z.w.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

m = A("m")
k = B("k")
d = A("d")
g = A("g")
h = B("h")
i = B("i")
b = B("b")
l = B("l")

m.z = k
k.w = g
d.z = h
g.z = k
h.w = d
i.w = d
b.w = m
l.w = m
assert d.z.w.z.w.z.txt == "h"