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

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

g = A("g")
h = B("h")
c = B("c")

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

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

g = A("g")
h = B("h")
c = B("c")

g.x = c
h.s = g
h.x = c
c.s = g
c.x = h
assert h.x.x.x.txt == "c"