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

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

i = A("i")
c = B("c")
h = A("h")
f = B("f")

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

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

i = A("i")
c = B("c")
h = A("h")
f = B("f")

i.y = f
c.s = f
c.x = h
h.y = f
f.s = c
f.x = i
assert f.s.x.y.txt == "f"