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

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

k = A("k")
h = B("h")
n = A("n")
m = B("m")
i = A("i")
c = B("c")
g = A("g")
e = B("e")

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

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

k = A("k")
h = B("h")
n = A("n")
m = B("m")
i = A("i")
c = B("c")
g = A("g")
e = B("e")

k.z = e
h.w = c
n.z = e
m.w = c
i.z = h
c.w = h
g.z = c
e.w = c
assert m.w.w.w.w.w.txt == "c"