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

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

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

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

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

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

k.z = b
d.r = h
m.r = e
e.r = h
g.z = m
l.z = b
n.z = b
b.r = h
i.z = h
h.r = d
assert k.z.r.r.txt == "d"