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

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

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

h.s = f
i.w = d
i.s = h
d.w = i
d.s = h
f.s = h
assert i.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

h.s = f
i.w = d
i.s = h
d.w = i
d.s = h
f.s = h
assert i.w.w.w.txt == "d"