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

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

k = A("k")
l = B("l")
b = B("b")
h = A("h")
j = A("j")
f = A("f")
i = B("i")

k.z = j
l.r = j
b.r = h
h.z = j
j.z = h
f.z = h
i.r = h
assert i.r.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

k = A("k")
l = B("l")
b = B("b")
h = A("h")
j = A("j")
f = A("f")
i = B("i")

k.z = j
l.r = j
b.r = h
h.z = j
j.z = h
f.z = h
i.r = h
assert i.r.z.z.z.z.z.z.txt == "h"