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

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

g = A("g")
d = B("d")
e = A("e")
b = B("b")
i = A("i")

g.s = d
d.s = i
e.s = d
b.s = i
i.s = b
assert g.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

g = A("g")
d = B("d")
e = A("e")
b = B("b")
i = A("i")

g.s = d
d.s = i
e.s = d
b.s = i
i.s = b
assert g.s.s.s.s.txt == "i"