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

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

d = A("d")
f = B("f")
k = B("k")
h = B("h")
m = B("m")
a = B("a")
n = A("n")

d.o = a
f.z = h
k.z = a
h.z = f
m.z = h
a.z = f
n.o = m
assert f.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

d = A("d")
f = B("f")
k = B("k")
h = B("h")
m = B("m")
a = B("a")
n = A("n")

d.o = a
f.z = h
k.z = a
h.z = f
m.z = h
a.z = f
n.o = m
assert f.z.z.z.z.txt == "f"