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

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

k = A("k")
b = B("b")
m = B("m")
n = B("n")
j = B("j")
l = A("l")
c = B("c")
h = B("h")
d = A("d")

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

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

k = A("k")
b = B("b")
m = B("m")
n = B("n")
j = B("j")
l = A("l")
c = B("c")
h = B("h")
d = A("d")

k.z = d
k.r = n
b.z = n
m.z = j
n.z = c
j.z = b
l.z = k
l.r = m
c.z = n
h.z = b
d.z = k
d.r = j
assert m.z.z.z.txt == "n"