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

h = A("h")
c = B("c")
d = A("d")
i = A("i")
g = B("g")
b = A("b")

h.s = g
c.z = i
d.s = c
i.s = c
g.z = d
b.s = g
assert h.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

h = A("h")
c = B("c")
d = A("d")
i = A("i")
g = B("g")
b = A("b")

h.s = g
c.z = i
d.s = c
i.s = c
g.z = d
b.s = g
assert h.s.z.s.txt == "c"