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

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

h = A("h")
i = B("i")
n = A("n")
j = B("j")
f = B("f")

h.s = j
h.y = i
i.z = h
n.s = f
n.y = j
j.z = h
f.z = h
assert f.z.y.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: B = None
        self.txt = txt

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

h = A("h")
i = B("i")
n = A("n")
j = B("j")
f = B("f")

h.s = j
h.y = i
i.z = h
n.s = f
n.y = j
j.z = h
f.z = h
assert f.z.y.z.y.z.txt == "h"