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

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

f = A("f")
c = B("c")
m = A("m")
e = A("e")
h = B("h")

f.s = c
c.z = m
m.s = h
e.s = c
h.z = f
assert c.z.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

f = A("f")
c = B("c")
m = A("m")
e = A("e")
h = B("h")

f.s = c
c.z = m
m.s = h
e.s = c
h.z = f
assert c.z.s.z.s.txt == "c"